赞
踩
- #include <iostream>
-
- using namespace std;
-
-
- //学生
- class St
- {
- //私有
- private:
- string name; //名
- int age; //年龄
- double score; //分数
-
- public:
- //无参构造
- St(){cout<<"Stu::无参构造"<<endl;}
- //有参构造
- St(string n,int a,double s):name(n),age(a),score(s) {cout<<"St::有参构造"<<endl;}
-
- //show函数
- void show()
- {
- cout<< "name="<< name <<endl;
- cout<< "age="<< age <<endl;
- cout<< "score="<< score <<endl;
- }
-
- //析构函数
- ~St(){cout<<"St::析构函数"<<endl;}
-
- };
-
-
- //党组织
- class Party
- {
- private:
-
- string act; // 活动
- string org; // 组织
-
-
- public:
-
- //无参构造
- Party(){}
- //有参构造
- Party(string n,string m):act(n),org(m) { cout<<"Stu::有参构造"<<endl;}
-
-
-
- //show函数
- void show()
- {
- cout<< "act="<< act <<endl;
- cout<< "org="<< org <<endl;
- }
-
- //析构函数
- ~Party(){cout<<"Party::析构函数"<<endl;}
-
- };
-
- //学生领导
- class Leader : public St,public Party
- {
- private:
- string post; //职位
- public:
-
- //无参构造
- Leader(){}
- // Leader():St("美眉",18,99.9),Party("sleep","we are dog"){}
-
- //有参构造
- Leader(string q,int a,double s,string c,string o,string n):St(q,a,s),Party(c,o),post(n)
- {
- // cout<<"有参构造"<<endl;
- }
-
-
- //show函数
- void show()
- {
- this->St::show();
-
- this->Party::show();
-
-
-
- cout<< "post="<<this->post <<endl;
-
- }
-
- //析构函数
- ~Leader(){cout<<"Leader::析构函数"<<endl;}
-
- };
-
-
- int main()
- {
-
- // St p1("ff",18,91);
-
- // p1.show();
-
- // Party p2("eat","we are pig");
- // p2.show();
-
-
- Leader p("王五",91,9,"吃吃吃","猪猪团","跑腿的");
- // Leader p("11",1,11,"5435","321","123");
-
- p.show();
-
-
- return 0;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。