1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include <iostream> using namespace std; #include<cstring> class CStaff { protected: int number; char name[10]; int age; public: CStaff(int num, const char *na, int a) { number = num; age = a; strcpy(name, na); } void Display() { cout << name << " is a Staff " << age << " yeas old" << endl; } }; class CTeacher : virtual public CStaff { protected: char zch[20]; public: CTeacher(int num, const char *na, int a, const char *zc); void Display() { cout << name << " is a Teacher " << age << " yeas old, " << zch << endl; } }; CTeacher::CTeacher(int num, const char *na, int a, const char *zc) : CStaff(num, na, a){ strcpy(zch, zc); } class CManagement : virtual public CStaff { protected: char zw[50]; public: CManagement(int num, const char *na, int a, const char *z); void Display() { cout << name << " is a management " << age << " yeas old, " << zw << endl; } }; CManagement::CManagement(int num, const char *na, int a, const char *z): CStaff(num, na, a) { strcpy(zw, z); } class CTeacherManagement : virtual public CTeacher, virtual public CManagement { public: CTeacherManagement(int num, const char *na, int a, const char *zc, const char *z); void Display() { cout << name << " is a Teacher management " << age << " yeas old, " << zch << ", " << zw << endl; } }; CTeacherManagement::CTeacherManagement(int num, const char *na, int a, const char *zc, const char *z) : CStaff(num, na, a), CTeacher(num, na, a, zc), CManagement(num, na, a, z) { } int main() { CStaff s1(101, "Zhao", 20); CTeacher t1(102, "Zhang", 30, "Lecture"); CManagement m1(103, "Wang", 50, "dean"); CTeacherManagement tm1(104, "Li", 40, "Peofessor", "department head"); s1.Display(); t1.Display(); m1.Display(); tm1.Display(); return 0; }
|