!!!!!!!

#include <iostream>
using namespace std;

class Human{
    private:
        string name;
        int age;
    public:
        Human(){cout<<"human的无参构造函数"<<endl;}
        Human(string n,int a)
            :name(n),age(a)
        {
            cout<<"human的有参构造函数"<<endl;
        }
        ~Human(){cout<<"human的析构函数"<<endl;}
        void show()
        {
            cout<<"human::"<<"姓名:"<<name<<" 年龄:"<<age<<endl;
        }
};

//学生类
class Student:public Human{
    private:
        double score;
    public:
        Student(){cout<<"student的无参构造函数"<<endl;}
        Student(string n,int a,double s)
            :Human(n,a),score(s){cout<<"student的有参构造函数"<<endl;}
        ~Student(){cout<<"student的析构函数"<<endl;}
        void show()
        {
            cout<<"student的show()"<<endl;
            Human::show();
            cout<<"成绩:"<<score<<endl;
        }
};

//党员类
class Party:public Human{
    private:
        string activity;        //党组织活动
        string party;
    public:
        Party(){cout<<"party的无参构造函数"<<endl;}
        Party(string n,int a,string act,string p)
            :Human(n,a),activity(act),party(p){cout<<"party的有参构造函数"<<endl;}
        ~Party(){cout<<"party的析构函数"<<endl;}
        void show()
        {
            cout<<"part的show()"<<endl;
            Human::show();
            cout<<"党组织活动:"<<activity<<" 党派:"<<party<<endl;
        }
};

//学生干部
class StudentCadre:public Student,public Party{
    private:
        string position;//职务
    public:
        StudentCadre(){cout<<"studentcadre的无参构造函数"<<endl;}
        StudentCadre(string n,int a,double s,string act,string p,string pos)
            :Student(n,a,s),Party(n,a,act,p),position(pos){cout<<"studentcadre的有参构造函数"<<endl;}
        ~StudentCadre(){cout<<"studentcadre的析构函数"<<endl;}
        void show()
        {
            cout<<"studentcadre的show()"<<endl;
            Student::show();
            Party::show();
            cout<<"职务:"<<position<<endl;
        }
};

int main()
{
    StudentCadre sc("张三",18,90,"党员活动","共产党","班长");
    sc.show();
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值