C++第五次实验

来源:互联网 发布:复杂网络画图 编辑:程序博客网 时间:2024/05/17 04:30
  1. #include<iostream>  
  2. #include<string>  
  3. using namespace std;  
  4.   
  5. class Teacher  
  6. {  
  7. public:  
  8.     Teacher(string n,string s,int a,string t);  
  9.     void display();  
  10.     string sex;  
  11.     string name;  
  12.     int age;  
  13.     string title;  
  14. };  
  15. Teacher::Teacher(string n,string s,int a,string t)    
  16. { name=n;sex=s;age=a;title=t;  }  
  17. void Teacher::display()  
  18. {  
  19.     cout<<"姓名"<<name<<endl;  
  20.     cout<<"性别"<<sex<<endl;  
  21.     cout<<"年龄"<<age<<endl;  
  22.     cout<<"职称"<<title<<endl;  
  23. }  
  24. class Cadre  
  25. {  
  26. public:  
  27.     Cadre(string n,string s,int a,string p);  
  28.     string sex;  
  29.     string name;  
  30.     int age;  
  31.     string post;  
  32. };  
  33. Cadre::Cadre(string n,string s,int a,string p)  
  34. {  
  35.     name=n;sex=s;age=a;post=p;  
  36. }  
  37. class Teacher_Cadre:public Teacher,public Cadre  
  38. {  
  39. public:  
  40.     Teacher_Cadre(string n,string s,int a,string t,string p,double w);  
  41.     void show();  
  42.     double wages;  
  43. };  
  44.   
  45. Teacher_Cadre::Teacher_Cadre(string n,string s,int a,string t,string p,double w):Teacher(n,s,a,t),Cadre(n,s,a,p),wages(w){}   
  46. void Teacher_Cadre::show()  
  47. {  
  48.     display();  
  49.     cout<<"职务"<<post<<endl;  
  50.     cout<<"薪水"<<wages<<endl;  
  51. }  
  52. int main()  
  53. {  
  54.     Teacher_Cadre t1("曾辉","男",42,"副教授","主任",1534.5);  
  55.     t1.show();  
  56.     return 0;  
  57. }  
0 0