标签:des style io color os ar for sp 数据
5-3 多级派生类的构造函数要求定义一个基类protected的数据成员:姓名sex(char类型);一个构造函数用于对数据成员初始化。
Employee,增加两个数据成员 基本工资 leaveDays(Employee类的公有派生类);为它定义初始化成员信息的构造函数,和显示数据成员信息的成员函数共如示例数据所示,共<font face=‘\"Times‘ new="" roman,="" serif\"="">5行,分别代表姓名、年龄、性别、基本工资、请假天数、业绩
Jerry m 32 4200 1 100
name:Jerry
age:32
sex:m
basicSalary:4200
leavedays:1
performance: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>
标签:des style io color os ar for sp 数据
原文地址:http://blog.csdn.net/lucky_vikey/article/details/40683821