C++ 实现超清晰大学管理系统:涵盖学生、职工、教师、助教全角色
首先,我们需要创建一个虚基类Person,包含姓名(name)和唯一标识符(id)属性,以及一个输出函数(show)。 ```cpp #include <iostream> #include <string> class Person { public: Person(const std::string& name, int id) : name_(name), id_(id) {} virtual void show() const = 0; protected: std::string name_; int id_; }; ``` 接下来,我们创建Employee类,继承自Person类,并添加部门(dept)和薪水(salary)属性,以及一个输出函数(show)。 ```cpp class Employee : public Person { public: Employee(const std::string& name, int id, const std::string& dept, double salary) : Person(name, id), dept_(dept), salary_(salary) {} void show() const override { std::cout << "Employee: " << name_ << ", ID: " << id_ << ", Department: " << dept_ << ", Salary: " << salary_ << std::endl; } private: std::string dept_; double salary_; }; ``` 然后,我们创建Student类,继承自Person类,并添加专业(major)和年级(level)属性,以及一个输出函数(show)。 ```cpp class Student : public Person { public: Student(const std::string& name, int id, const std::string& major, int level) : Person(name, id), major_(major), level_(level) {} void show() const override { std::cout << "Student: " << name_ << ", ID: " << id_ << ", Major: " << major_ << ", Level: " << level_ << std::endl; } private: std::string major_; int level_; }; ``` 接下来,我们创建Teacher类,继承自Employee类,并添加职称(title)属性,以及一个输出函数(show)。 ```cpp class Teacher : public Employee { public: Teacher(const std::string& name, int id, const std::string& dept, double salary, const std::string& title) : Employee(name, id, dept, salary), title_(title) {} void show() const override { std::cout << "Teacher: " << name_ << ", ID: " << id_ << ", Department: " << dept_ << ", Salary: " << salary_ << ", Title: " << title_ << std::endl; } private: std::string title_; }; ``` 我们创建Assistant类,继承自Employee类和Student类,并添加一个输出函数(show)。 ```cpp class Assistant : public Employee, public Student { public: Assistant(const std::string& name, int id, const std::string& dept, double salary, const std::string& major, int level) : Employee(name, id, dept, salary), Student(name, id, major, level) {} void show() const override { std::cout << "Assistant: " << name_ << ", ID: " << id_ << ", Department: " << dept_ << ", Salary: " << salary_ << ", Major: " << major_ << ", Level: " << level_ << std::endl; } }; ``` 在main函数中使用这些类: ```cpp int main() { Person p("John Doe", 1); Employee e("Jane Smith", 2, "HR", 50000); Student s("Alice Johnson", 3, "Computer Science", 2); Teacher t("Bob Brown", 4, "Mathematics", 60000, "Professor"); Assistant a("Charlie Green", 5, "Physics", 40000, "Mechanics", 3); p.show(); e.show(); s.show(); t.show(); a.show(); return 0; } ``` ######[AI写代码神器 | 1014点数解答 | 2024-05-29 18:22:53]
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)343
- 工程师必备!10 种工程日常易用管理工具大揭秘(百度文心 | 346点数解答 | 2023-11-09 18:26:09)290
- 魂牵梦绕七彩丹霞:一场与自然的深情邂逅(字节豆包 | 1268点数解答 | 2024-12-23 19:56:52)184
- Photoshop 脚本:海边图像清晰调整示例全揭秘(字节豆包 | 160点数解答 | 2025-02-06 16:30:37)237
- Photoshop脚本:让海边照片瞬间清晰,附超详细示例及要点!(DeepSeek | 426点数解答 | 2025-03-02 12:27:39)180
- Java程序模拟教学选课:林老师开课,58 位学生选课男女比例大揭秘( | 2653点数解答 | 2024-04-02 11:00:16)470
- Java程序设计课程:模拟教学管理,统计58位选课学生男女比重( | 363点数解答 | 2024-04-05 18:31:39)473
- R语言实战:用配对样本t检验评估课程强化集训对学生成绩的提升效果(GPT | 630点数解答 | 2024-11-26 22:00:01)321
- 51 单片机:定时器 0 实现 8 个 LED 循环点亮,附代码及优化建议(字节豆包 | 1193点数解答 | 2024-12-27 15:10:29)310
- C++实现单门课程成绩管理系统:教师学生双身份操作全解析(GPT | 6361点数解答 | 2024-05-24 02:01:02)534
- C++ 实现超实用单门课程成绩管理系统,教师学生灵活使用! (GPT | 68点数解答 | 2024-05-24 10:17:09)330
- C++实现:功能完备的单门课程成绩管理系统(GPT | 4293点数解答 | 2024-05-24 10:20:03)376