Sdut 5-2 constructor of the derived class

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

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.