#include <iostream>
using namespace std;
class Human{
private:
int age;
string name;
public:
Human()
{
cout<<"Human无参构造!\n";
age = 0;
name = "";
}
Human(const int a,const string b):age(a),name(b)
{
cout<<"Human有参构造!\n";
}
~Human(){
cout<<"Human析构函数!\n";
}
void show(){
cout<<"age="<<age<<"\nname="<<name<<endl;
}
};
class Student : public Human{
private:
float score;
public:
Student()
{
cout<<"Student无参构造!\n";
score = 0;
}
Student(const int a,const string b,const float c):Human(a,b),score(c)
{
cout<<"Student有参构造!\n";
}
~Student()
{
cout<<"Student析构函数!\n";
}
void show(){
Human::show();
cout<<"score="<<score<<endl;
}
};
class Party : public Human{
private:
string activity;
string organization;
public:
Party()
{
cout<<"Party无参构造!\n";
activity="";
organization="";
}
Party(const int a,const string b,const string c,const string d):Human(a,b),activity(c),organization(d)
{
cout<<"Party有参构造!\n";
}
~Party()
{
cout<<"Party析构函数!\n";
}
void show(){
Human::show();
cout<<"activity="<<activity<<endl;
cout<<"organization="<<organization<<endl;
}
};
class Cadre : public Party,public Student{
private:
string position;
public:
Cadre()
{
cout<<"Cadre无参构造!\n";
position="";
}
Cadre(const int a,const string b,const float c,const string d,const string e,const string f)
:Student(a,b,c),Party(a,b,d,e),position(f)
{
cout<<"Cadre有参构造!\n";
}
~Cadre()
{
cout<<"Cadre析构函数!\n";
}
void show(){
Student::show();
Party::show();
cout<<"position="<<position<<endl;
}
};
int main(int argc, const char *argv[])
{
Cadre c;
c.show();
cout<<endl;
Cadre c2(18,"张三",96.3,"活动","组织","岗位");
c2.show();
return 0;
}
09-03
97
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-03
106
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-15
1152
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)