封装Person 类
name,age,sex
给出show方法要输出上面三条信息
封装Employee 职员 继承自Person
salary, work_id
给出show方法要输出除了Person类中基本的情况之外 再输出salary, work_id
封装Manager 管理者 继承自Employee
position 职位
给出show方法要输出除了Employee类中基本的情况之外 再输出position
#include <iostream>
using namespace std;
class Person{
private:
string name;
int age;
string sex;
public:
Person(string name,int age,string sex){
this->name=name;
this->age=age;
this->sex=sex;
}
void show(){
cout<<name<<" "<<age<<" "<<sex<<endl;
}
};
class Employee:public Person{ //职员类继承自Person类
private:
double salary;
string work_id;
public:
Employee(string name,int age,string sex,double salary,string work_id):Person(name,age,sex){
this->salary=salary;
this->work_id=work_id;
}
void show(){
Person::show();
cout<<salary<<" "<<work_id<<endl;
}
};
class Manager:public Employee{
private:
string position;
public:
//指明直接基类的构造函数函数如何调用
Manager(string name,int age,string sex,double salary,string work_id,string position)
:Employee(name,age,sex,salary,work_id)
{
this->position=position;
}
void show(){
Employee::show();
cout<<position<<endl;
}
};
int main()
{
Manager m("老吴",40,"男",8000,"007","经理");
m.show();
}