5-2 constructor of the derived class Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^ Description
Through this exercise, you can understand the definition and usage of the derived class constructor.
Define a base class person with three protected data members: Name (char * type), gender sex (char type), age (INT type ); A constructor is used to initialize data members. A member function show () is used to output data member information.
Create a public derived class employee of the person class, add two data members, basic salary basicsalary (INT type), leave days, leavedays (INT type), and define the constructor for initializing member information, and show ().
Input
A total of five data items are displayed, including name, gender, age, basic salary, and leave days.
Output
As shown in the sample data, there are five rows, representing the name, age, gender, basic salary, and leave days respectively.
Sample Input
zhangsan m 30 4000 2
Sample output
name:zhangsanage:30sex:mbasicSalary:4000leavedays:2
Prompt Source
#include <iostream>#include<string>using namespace std;class Person{protected : string name; char sex; int age;public : Person() { cin>>name>>sex>>age; } void show1() { cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; }};class Employee : public Person{private : int basicsalary; int leavedays;public : Employee() { cin>>basicsalary>>leavedays; } void show() { show1(); cout<<"basicSalary:"<<basicsalary<<endl; cout<<"leavedays:"<<leavedays<<endl; }};int main(){ Employee e; e.show(); return 0;}
Sdut 5-2 constructor of the derived class