C++ 多重继承实现学生干部类 - 示例代码
#include
class Student { protected: string name; char sex; int ID; float score; public: void display() { cout << 'Name: ' << name << endl; cout << 'Sex: ' << sex << endl; cout << 'ID: ' << ID << endl; cout << 'Score: ' << score << endl; } };
class Cadre { protected: string name; char sex; int ID; string post; public: void display() { cout << 'Name: ' << name << endl; cout << 'Sex: ' << sex << endl; cout << 'ID: ' << ID << endl; cout << 'Post: ' << post << endl; } };
class Student_Cadre : public Student, public Cadre { private: double wages; public: void display() { Student::display(); cout << 'Post: ' << post << endl; cout << 'Wages: ' << wages << endl; } };
int main() { Student_Cadre sc; sc.name = 'Tom'; sc.sex = 'M'; sc.ID = 1001; sc.score = 95.5; sc.post = 'Monitor'; sc.wages = 1000.0; sc.display(); return 0; }
原文地址: https://www.cveoy.top/t/topic/ocqy 著作权归作者所有。请勿转载和采集!