教师兼干部类

来源:互联网 发布:淘宝女鞋文案 编辑:程序博客网 时间:2024/04/29 12:45
  1. #include <iostream>  
  2. #include <string>  
  3. using namespace std;  
  4.   
  5. class Teacher  
  6. {  
  7. public:  
  8.     Teacher(string nam,int ag, string se, string add, string pho, string tit):  
  9.         name(nam),age(ag),sex(se),addr(add),phone(pho),title(tit){}  
  10.     void display();  
  11. protected:  
  12.     string name;  
  13.     int age;  
  14.     string sex;  
  15.     string addr;  
  16.     string phone;  
  17.     string title;  
  18. };  
  19.   
  20. void Teacher::display()  
  21. {  
  22.     cout << " 姓名:" << name << endl;  
  23.     cout << " 年龄:" << age << endl;  
  24.     cout << " 性别:" << sex << endl;  
  25.     cout << " 地址:" << addr << endl;  
  26.     cout << " 电话:" << phone << endl;  
  27.     cout << " 职称:" << title << endl;  
  28. }  
  29.   
  30. class Cadre  
  31. {  
  32. public:  
  33.     Cadre(string nam,int ag, string se, string add, string pho, string pos):  
  34.         name(nam),age(ag),sex(se),addr(add),phone(pho),post(pos){}  
  35.     void display();  
  36. protected:  
  37.     string name;  
  38.     int age;  
  39.     string sex;  
  40.     string addr;  
  41.     string phone;  
  42.     string post;  
  43. };  
  44.   
  45. void Cadre::display()  
  46. {  
  47.     cout << " 姓名:" << name << endl;  
  48.     cout << " 年龄:" << age << endl;  
  49.     cout << " 性别:" << sex << endl;  
  50.     cout << " 地址:" << addr << endl;  
  51.     cout << " 电话:" << phone << endl;  
  52.     cout << " 职务:" << post << endl;  
  53. }  
  54.   
  55. class Teacher_Cadre: public Teacher,public Cadre  
  56. {  
  57. public:  
  58.     Teacher_Cadre(string nam,int ag, string se, string add, string pho, string tit, string pos,int wage):  
  59.         Teacher(nam,ag,se,add,pho,tit),Cadre(nam,ag,se,add,pho,pos),wages(wage){}  
  60.     void show();  
  61. private:  
  62.     int wages;  
  63. };  
  64.   
  65. void Teacher_Cadre::show()  
  66. {  
  67.     Teacher::display();  
  68.     cout << " 职务:" << post << endl;  
  69.     cout << " 工资:" << wages << endl;  
  70. }  

测试函数:

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. int main()  
  2. {  
  3.     Teacher_Cadre F("Bob",25,"male","New York","000-0000","senior teacher","director",5000);  
  4.     F.show();  
  5.     return 0;  
  6. }  
0 0