酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

用c++建立一个简单的大学管理系统。 其中有学生和职工,职工中有教师,学生中有助教。 person虚基类 姓名(name), 唯一标识符(id),输出函数(show) employee类 新增:部门(dept),薪水(salary),输出函数(show) student类 新增:专业(major),年级(level),输出函数(show) teacher类 新增:职称(title),输出函数(show) assistant类 新增:输出函数(show) 要求:teacher类继承职工类,assistant类继承employee类和student类,employee类继承person虚基类,student继承person虚基类 在main函数中使用这些类。

以下是一个简单的C++大学管理系统的示例代码: ```cpp #include <iostream> #include <string> using namespace std; // 虚基类 class Person { protected: string name; int id; public: void setName(string n) { name = n; } void setId(int i) { id = i; } void show() { cout << "姓名:" << name << endl; cout << "唯一标识符:" << id << endl; } }; // 职工类 class Employee : virtual public Person { protected: string dept; double salary; public: void setDept(string d) { dept = d; } void setSalary(double s) { salary = s; } void show() { Person::show(); cout << "部门:" << dept << endl; cout << "薪水:" << salary << endl; } }; // 学生类 class Student : virtual public Person { protected: string major; int level; public: void setMajor(string m) { major = m; } void setLevel(int l) { level = l; } void show() { Person::show(); cout << "专业:" << major << endl; cout << "年级:" << level << endl; } }; // 教师类 class Teacher : public Employee { protected: string title; public: void setTitle(string t) { title = t; } void show() { Employee::show(); cout << "职称:" << title << endl; } }; // 助教类 class Assistant : public Employee, public Student { public: void show() { Employee::show(); Student::show(); } }; int main() { Teacher t; t.setName("张三"); t.setId(10001); t.setDept("计算机科学与技术"); t.setSalary(8000.00); t.setTitle("教授"); t.show(); cout << endl; Assistant a; a.setName("李四"); a.setId(20001); a.setDept("数学与统计学"); a.setSalary(5000.00); a.setMajor("应用数学"); a.setLevel(3); a.show(); return 0; } ``` 这个示例中,每个类都继承了相应的基类,并实现了自己的输出函数(show)。在main函数中,创建了一个教师对象和一个助教对象,并设置了相应的信息。然后调用对象的show函数,输出对象的信息。 希望这个示例可以帮助你理解如何在C++中建立一个简单的大学管理系统。 [2024-05-29 18:23:32 | AI写代码神器 | 1431点数解答]

相关提问