修改习题4-36中的基类CPerson和派生类CEmployee,为他们定义构造函数,要求派生类CEmployee的构造函数现实调用基类CPerson的构造函数。
//HW_CH04_40
/*
修改习题4-36中的基类CPerson和派生类CEmployee,
为他们定义构造函数,
要求派生类CEmployee的构造函数现实调用基类CPerson的构造函数。
*/
#include<iostream>
#include<string>
using namespace std;
class CPerson {
private:
string name;
string ID;
bool gender;
int age;
public:
CPerson(string name, string ID, bool gender, int age) {
this->name = name;
this->ID = ID;
this->gender = gender;
this->age = age;
}
string getname() {
return name;
}
string getID() {
return ID;
}
bool getgender() {
return gender;
}
int getage() {
return age;
}
};
class CEmployee :public CPerson {
private:
string department;
int salary;
public:
CEmployee(string name, string ID, bool gender, int age,string department, float salary):CPerson(name,ID,gender,age) {
this->department = department;
this->salary = salary;
}
void show(CEmployee& e) {
cout << e.getname() << " is in " << department << endl;
cout << "he is " << e.getage() << " years old" << endl;
cout << "the pay of work is:" << salary << "¥" << endl;
}
};
int main() {
CEmployee e("liulu", "202124033", 1, 43, "计算机系", 1000000000);
e.show(e);
}