要求:
(1)在Person类中包含的数据成员有姓名(name)、年龄(age)、性别(sex)。在Teacher类还包含数据成员职称(title),在Cadre类中还包含数据成员职务(post),在TeacherCadre类中还包含数据成员工资(wages)。
(2)在类体中定义成员函数。
(3)每个类都有构造函数与显示信息函数(Show)。
#include"iostream" using namespace std; class person{ private: char name[18]; int age; char sex; public: person(char *a,int b,char c):age(b),sex(c){ strcpy(name,a); } void Show(){ cout << name << " " << age << " " << sex << " " ; } }; class Teacher:virtual public person { private: char title[8]; public: Teacher(char *a,int b,char c,char *d):person(a,b,c){ strcpy(title,d); } void Show(){ person::Show(); cout << title << endl ; } void gettitle(){ cout << title << " " ; } }; class Cadre:virtual public person{ private : char post[8]; public: Cadre(char *a,int b,char c,char *d):person(a,b,c){ strcpy(post,d); } void Show(){ person::Show(); cout << post << endl ; } void getCadre(){ cout << post << " " ; } }; class TeacherCadre: public Teacher, public Cadre{ private: int wages; public: TeacherCadre(char *a,int b,char c,char *d,char *e,int f):Teacher(a,b,c,d),Cadre(a,b,c,e),wages(f),person(a,b,c){}; void Show(){ person::Show(); Teacher::gettitle(); Cadre::getCadre(); cout << wages << endl ; } }; void main() { TeacherCadre t("liu",20,'m',"teacher","teach",1000); t.Show(); }