C++day3作业

#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;
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值