参照书本150页例5.13
#include<iostream>
#include<string>
using namespace std;
class base{
public:
base(string i,int j)
{
name=i;
age=j;
}
void show()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
}
private:
string name;
int age;
};
class leader: virtual public base{
public:
leader(string i,int j,string k,string l):base(i,j){
post=k;
dept=l;
}
void show()
{
base::show();
cout<<"职务:"<<post<<endl;
cout<<"部门:"<<dept<<endl;
}
private:
string post;
string dept;
};
class engieer:virtual public base{
public:
engieer(string i,int j,string a,string b):base(i,j)
{
title=a;
major=b;
}
void show()
{
base::show();
cout<<"职称:"<<title<<endl;
cout<<"专业:"<<major<<endl;
}
private:
string title;
string major;
};
class chairman:public leader,public engieer{
public:
chairman(string i,int j,string k,string l,string a,string b):base(i,j),leader(i,j,k,l),engieer(i,j,a,b)
{
cout<<"主任工程师"<<endl;
base::show();
cout<<"职务:"<<i<<endl;
cout<<"部门:"<<j<<endl;
cout<<"职称:"<<a<<endl;
cout<<"专业:"<<b<<endl;
}
};
int main()
{
base b("华庆",22);
b.show();
cout<<"----------------------------"<<endl;
leader lea("鹿仁杰",19,"主任","管理部");
lea.show();
cout<<"----------------------------"<<endl;
engieer eng("鲁任矣",24,"网络工程师","计算机专业");
eng.show();
cout<<"----------------------------"<<endl;
chairman cha1("波仕",40,"主任","管理部","工程师","管理专业");
system("pause");
return 0;
}