5-3 constructor of multi-level derived classes Time Limit: 1000 ms memory limit: 65536 K Description
Define a data member of the base class protected: Name sex (char type); a constructor is used to initialize data members.
Employee: Add two basic salary leavedays (public derived class of the employee class) for the data member, and define the constructor for initializing the member information for it, and the member functions that display data member information are shown in the sample data. A total of <font face = '\ "Times' New =" "Roman, = "" serif \ "=" "> five rows: name, age, gender, basic salary, leave days, and performance
Sample Input
Jerry m 32 4200 1 100
Sample output
name:Jerryage:32sex:mbasicSalary:4200leavedays:1performance:100
<span style="font-size:18px;">#include<iostream>#include<string>using namespace std;class person{ protected: string name; string sex; int age; public: person(string n,string s,int a):name(n),sex(s),age(a){} void display() { cout<<"name:"<<name<<endl; cout<<"age:"<<age<<endl; cout<<"sex:"<<sex<<endl; }};class emp:public person{private: int salary; int day;public: emp(string n,string s,int a,int sa,int d):person(n,s,a),salary(sa),day(d){} void show() { cout<<"basicSalary:"<<salary<<endl; cout<<"leavedays:"<<day<<endl; }};class manager:public emp{private: int per;public: manager(string n,string s,int a,int sa,int d,int p):emp(n,s,a,sa,d),per(p){} void show() { cout<<"performance:"<<per<<endl; }};int main(){ string name,sex; int age,salary,day,per; cin>>name>>sex>>age>>salary>>day>>per; person p(name,sex,age); emp e(name,sex,age,salary,day); manager m(name,sex,age,salary,day,per); p.display(); e.show(); m.show();}</span>
5-3 constructor of multi-level derived classes