#include <iostream>
#include<string>
using namespace std;
class base
{
public:
base(int a,string na)
{
age=a;
name=na;
}
~base(){}
virtual void display()=0;
protected:
int age;
string name;
};
class leader:virtual public base
{
public:
leader(int a,string na,string zhi,string dep):base(a,na)
{
zhiwei=zhi;
depart=dep;
}
~leader(){}
void display()
{
cout<<"姓名 "<<name<<"年龄 "<<age<<"职位 "<<zhiwei<<"部门 "<<depart<<endl;
}
protected:
string zhiwei;
string depart;
};
class engineer:virtual public base
{
public:
engineer(int a,string na,string zhic,string car):base(a,na)
{
zhicheng=zhic;
career=car;
}
void display()
{
cout<<"姓名 "<<name<<"年龄 "<<age<<"职称 "<<zhicheng<<"职业 "<<career<<endl;
}
~engineer(){}
protected:
string zhicheng;
string career;
};
class chairman:public leader, public engineer
{
public:
chairman(int a,string na,string zhi,string dep,string zhic,string car):base(a,na),leader(a,na,zhi,dep),engineer(a,na,zhic,car){}
void display()
{
cout<<"姓名 "<<name<<"年龄 "<<age<<"职称 "<<zhicheng<<"职业 "<<career<<"职位 "<<zhiwei<<"部门 "<<depart<<endl;
}
};
void main()
{
leader L(28,"三弟","书记","团委");
L.display();
engineer e(29,"二哥","助教","电子工程");
e.display();
chairman c(40,"一哥","主任","电子工程","教授","办公室");
c.display();
}
以前没试的,这个试了的,可以运行
#include<string>
using namespace std;
class base
{
public:
base(int a,string na)
{
age=a;
name=na;
}
~base(){}
virtual void display()=0;
protected:
int age;
string name;
};
class leader:virtual public base
{
public:
leader(int a,string na,string zhi,string dep):base(a,na)
{
zhiwei=zhi;
depart=dep;
}
~leader(){}
void display()
{
cout<<"姓名 "<<name<<"年龄 "<<age<<"职位 "<<zhiwei<<"部门 "<<depart<<endl;
}
protected:
string zhiwei;
string depart;
};
class engineer:virtual public base
{
public:
engineer(int a,string na,string zhic,string car):base(a,na)
{
zhicheng=zhic;
career=car;
}
void display()
{
cout<<"姓名 "<<name<<"年龄 "<<age<<"职称 "<<zhicheng<<"职业 "<<career<<endl;
}
~engineer(){}
protected:
string zhicheng;
string career;
};
class chairman:public leader, public engineer
{
public:
chairman(int a,string na,string zhi,string dep,string zhic,string car):base(a,na),leader(a,na,zhi,dep),engineer(a,na,zhic,car){}
void display()
{
cout<<"姓名 "<<name<<"年龄 "<<age<<"职称 "<<zhicheng<<"职业 "<<career<<"职位 "<<zhiwei<<"部门 "<<depart<<endl;
}
};
void main()
{
leader L(28,"三弟","书记","团委");
L.display();
engineer e(29,"二哥","助教","电子工程");
e.display();
chairman c(40,"一哥","主任","电子工程","教授","办公室");
c.display();
}
以前没试的,这个试了的,可以运行