5-3 constructor of multi-level derived classes

Source: Internet
Author: User
Tags class manager
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.