#include <iostream>
#include <string>
using namespace std;
class Human
{
private:
string name;
int age;
public:
Human(){} //无参构造函数
//有参构造函数
Human(string i_name,int i_age):name(i_name),age(i_age)
{
cout<<"调用了Human有参构造函数"<<endl;
}
~Human(){} //析构函数
void show()
{
cout<<"name:"<<name<<" age:"<<age<<endl;
return;
}
};
class Student:Human
{
private:
double score;
public:
Student(){} //无参构造函数
//有参构造函数
Student(string i_name,int i_age,double i_score):Human(i_name,i_age),score(i_score)
{
cout<<"调用了Student有参构造函数"<<endl;
}
~Student(){} //析构函数
void show()
{
Human::show();
cout<<"score:"<<score<<endl;
return;
}
};
class Party:Human
{
private:
string event;
string organization;
public:
Party(){} //无参构造函数
//有参构造函数
Party(string i_name,int i_age,string i_event,string i_organization)
:Human(i_name,i_age),event(i_event),organization(i_organization)
{
cout<<"调用了Party有参构造函数"<<endl;
}
~Party(){} //析构函数
void show()
{
Human::show();
cout<<"event:"<<event<<" organization:"<<organization<<endl;
return;
}
};
class Ganbu:Student,Party
{
private:
string position;
public:
Ganbu(){} //无参构造函数
//有参构造函数
// Ganbu(string s_name,int s_age,double s_score,string p_name,int p_age,string p_event,string p_organization,string i_position)
// :Student(s_name,s_age,s_score),Party(p_name,p_age,p_event,p_organization),position(i_position)
Ganbu(string name,int age,double s_score,string p_event,string p_organization,string i_position)
:Student(name,age,s_score),Party(name,age,p_event,p_organization),position(i_position)
{
cout<<"调用了Ganbu有参构造函数"<<endl;
}
~Ganbu(){} //析构函数
void show()
{
Student::show();
Party::show();
cout<<"position:"<<position<<endl;
}
};
int main(int argc, const char *argv[])
{
Ganbu xiaozou("小邹",21,99,"去山水庄园学习外语","汉东省京州市法院副院长","小组长");
xiaozou.show();
return 0;
}