当前位置:   article > 正文

C++day3作业

C++day3作业
  1. #include <iostream>
  2. using namespace std;
  3. //学生
  4. class St
  5. {
  6. //私有
  7. private:
  8. string name; //
  9. int age; //年龄
  10. double score; //分数
  11. public:
  12. //无参构造
  13. St(){cout<<"Stu::无参构造"<<endl;}
  14. //有参构造
  15. St(string n,int a,double s):name(n),age(a),score(s) {cout<<"St::有参构造"<<endl;}
  16. //show函数
  17. void show()
  18. {
  19. cout<< "name="<< name <<endl;
  20. cout<< "age="<< age <<endl;
  21. cout<< "score="<< score <<endl;
  22. }
  23. //析构函数
  24. ~St(){cout<<"St::析构函数"<<endl;}
  25. };
  26. //党组织
  27. class Party
  28. {
  29. private:
  30. string act; // 活动
  31. string org; // 组织
  32. public:
  33. //无参构造
  34. Party(){}
  35. //有参构造
  36. Party(string n,string m):act(n),org(m) { cout<<"Stu::有参构造"<<endl;}
  37. //show函数
  38. void show()
  39. {
  40. cout<< "act="<< act <<endl;
  41. cout<< "org="<< org <<endl;
  42. }
  43. //析构函数
  44. ~Party(){cout<<"Party::析构函数"<<endl;}
  45. };
  46. //学生领导
  47. class Leader : public St,public Party
  48. {
  49. private:
  50. string post; //职位
  51. public:
  52. //无参构造
  53. Leader(){}
  54. // Leader():St("美眉",18,99.9),Party("sleep","we are dog"){}
  55. //有参构造
  56. Leader(string q,int a,double s,string c,string o,string n):St(q,a,s),Party(c,o),post(n)
  57. {
  58. // cout<<"有参构造"<<endl;
  59. }
  60. //show函数
  61. void show()
  62. {
  63. this->St::show();
  64. this->Party::show();
  65. cout<< "post="<<this->post <<endl;
  66. }
  67. //析构函数
  68. ~Leader(){cout<<"Leader::析构函数"<<endl;}
  69. };
  70. int main()
  71. {
  72. // St p1("ff",18,91);
  73. // p1.show();
  74. // Party p2("eat","we are pig");
  75. // p2.show();
  76. Leader p("王五",91,9,"吃吃吃","猪猪团","跑腿的");
  77. // Leader p("11",1,11,"5435","321","123");
  78. p.show();
  79. return 0;
  80. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/431700
推荐阅读
相关标签
  

闽ICP备14008679号