#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;
}
02-08
530
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-27
06-08
09-02
476
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-29
2740
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-03
374
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-31
1870
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)