#include #include // --------------------------------------------------------------------------- // Class Definitions // --------------------------------------------------------------------------- class entity { private: static int current_id; int entity_id; protected: int getid() {return entity_id;} public: entity() { entity_id = current_id; current_id++; } virtual int id() = 0; }; int entity::current_id = 0; class person : public entity { private: char *name; int tel; public: person(char* str = NULL, int i = 0); int id() {return getid();}; void virtual print(); }; class student : virtual public person { private: char *degree; protected: void _print(); public: student(char* str, char* d = NULL, int t = 0); void print(); }; class employee : virtual public person { private: char *department; protected: void _print(); public: employee(char*, char* d = NULL, int i = 0); void print(); }; class ta : public student, public employee { private: char *duty; public: ta( char* n, char* deg = NULL, char* dept = NULL, char* work = NULL, int i = 0); void print(); }; // --------------------------------------------------------------------------- // constructors and member functions // --------------------------------------------------------------------------- person::person(char* str, int i) : entity() { if (str != NULL) { name = new char[strlen(str)+1]; strcpy(name, str); } else name = NULL; tel = i; } void person::print() { cout << "name: " << name << endl; cout << "tel: " << tel << endl; cout << "id: " << id() << endl; } student::student(char* n, char* d, int i) : person(n, i) { if (d != NULL) { degree = new char[strlen(d)+1]; strcpy(degree, d); } else degree = NULL; } void student::_print() { cout << "Degree : " << degree << endl; } void student::print() { person::print(); _print(); } employee::employee(char* n, char* d, int i) : person(n, i) { if (d != NULL) { department = new char[strlen(d)+1]; strcpy(department, d); } else department = NULL; } void employee::_print() { cout << "Department : " << department << endl; } void employee::print() { person::print(); _print(); } ta::ta(char* n, char* deg, char* dept, char* work, int t) : student(n, deg, t), employee(n, dept, t*10), person(n, t) { if (work != NULL) { duty = new char[strlen(work)+1]; strcpy(duty, work); } else duty = NULL; } void ta::print() { person::print(); student::_print(); employee::_print(); cout << "duty: " << duty << "\n"; } // --------------------------------------------------------------------------- // Main // --------------------------------------------------------------------------- void main(void) { person p1("William", 101); student s1("Paul", "Honour", 102); employee e1("Steve", "Dept. of CS", 103); ta t1("Albert", "MS", "CS", "C53", 104); cout << t1.student::id() << endl; cout << t1.employee::id() << endl; cout << t1.id() << endl; p1.print(); s1.print(); e1.print(); t1.print(); }