// 补充必要的头文件(原代码缺失) #include <iostream> #include <string> using namespace std; // 基类:人员基本信息 class Person // 类名首字母大写,符合C++命名规范 { private: int age; // 年纪 string name; // 姓名 string identity; // 身份(原shenfen,英文更易读) public: // 优化点1:string类型默认值改为空字符串"",而非NULL Person(int m_age = 0, string m_name = "", string m_identity = "") : age(m_age), name(m_name), identity(m_identity) { // 可选:增加参数合法性检查,增强健壮性 if (age < 0) age = 0; // 年龄不能为负数 } // 虚函数,为多态提供基础 virtual void show() const { cout << "信息如下:" << endl; cout << "年龄:" << age << endl; cout << "姓名:" << name << endl; cout << "身份:" << identity << endl; } }; // 派生类:学生 class Student : public Person { private: string education; // 学历(原xueli,英文更易读) public: // 优化点1:string默认值改为"" Student(int age = 0, string name = "", string identity = "", string m_education = "") : Person(age, name, identity), education(m_education) {} void show() const override // 补充override关键字,明确重写基类虚函数 { Person::show(); cout << "学历:" << education << endl; } }; // 派生类:老师 class Teacher : public Person { private: string teachingSubject; // 教学科目(原Subject,命名更清晰) public: // 优化点1:string默认值改为"",修正参数名拼写错误(原m_subjcet) Teacher(int age = 0, string name = "", string identity = "", string m_subject = "") : Person(age, name, identity), teachingSubject(m_subject) {} void show() const override { Person::show(); cout << "教学科目:" << teachingSubject << endl; } }; // 派生类:职工 class Employee : public Person { private: string workUnit; // 工作单位(原unit,命名更清晰) public: // 优化点1:string默认值改为"" Employee(int age = 0, string name = "", string identity = "", string m_unit = "") : Person(age, name, identity), workUnit(m_unit) {} void show() const override { Person::show(); cout << "工作单位:" << workUnit << endl; } }; // 派生类:在职读书的老师(原Study_Work,类名更直观) class TeacherWithStudy : public Person { private: string teachingSubject; // 教学科目(命名和Teacher类保持一致) string education; // 学历(命名和Student类保持一致) public: // 优化点1:string默认值改为"" TeacherWithStudy(int age = 0, string name = "", string identity = "", string m_subject = "", string m_education = "") : Person(age, name, identity), teachingSubject(m_subject), education(m_education) {} void show() const override { Person::show(); cout << "教学科目:" << teachingSubject << endl; cout << "学历:" << education << endl; } }; int main() { Person* p1 = nullptr, * p2 = nullptr, * p3 = nullptr, * p4 = nullptr; // 创建各派生类对象 Student st(22, "王五", "学生", "高中生"); p1 = &st; p1->show(); cout << endl; Teacher te(30, "张三", "老师", "数学"); p2 = &te; p2->show(); cout << endl; Employee em(45, "老王", "职工", "保安"); p3 = &em; p3->show(); cout << endl; TeacherWithStudy sw(26, "李四", "在职读书老师", "大学英语", "研究生"); p4 = &sw; p4->show(); return 0; }大学有这样几类人员:学生、教师、职员和在职读书的教师。给出这几类人员的类描述。
张小明
前端开发工程师
【JPCS出版,有ISSN号,高录用,EI稳检索,福州大学、青岛大学威海创新研究院联合主办,Fellow报告,会议有保障】2026年能源、电力与可持续发展国际学术会议(EESD 2026)
2026年能源、电力与可持续发展国际学术会议(EESD 2026) 2026 International Conference on Energy, Electricity and Sustainable Development 2026年3月6-8日 中国昆明(可线上参会) JPCS出版!有ISSN号,…
【广东工业大学主办,SAE出版,EI快速稳定检索,学术大咖加盟 | 低空经济、交通系统、机器制造、供应链网络、无人机等主题均可投递】 2026年低空经济与技术应用国际学术会议 (LETA 2026)
2026年低空经济与技术应用国际学术会议 (LETA 2026) 2026 International Conference on Low - altitude Economy and Technology Application 低空经济、交通系统、机器制造、技术应用、供应链网络、无人机等主题均可投递 SAE出版!EI&SCOPUS快速稳定检索&…
【悬臂梁挠度问题】基于PINN物理信息神经网络计算一维悬臂梁挠度问题附Python代码
✅作者简介:热爱科研的Matlab仿真开发者,擅长数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。 🍎 往期回顾关注个人主页:Matlab科研工作室 🍊个人信条:格物致知,完整Matlab代码及仿真…
软件时代正在终结?2026,一场静默的AI革命正重塑我们的工作与未来
当AI能自动写代码、维护系统、搬运数据,软件公司靠“复杂性”构筑的护城河,正在一夜干涸。就在几天前,硅谷四位顶级投资人的一场闭门对话,意外释放出一个令人警醒的信号:5000亿美元资本正悄然撤离软件赛道。这不是周期…
用了一年Cursor,我的代码能力反而退化了
昨天晚上,我盯着屏幕发了半小时呆。 不是在等编译,是在等AI生成代码——然后我发现,离开AI提示,我竟然写不出一个完整的React组件了。 手指悬在键盘上,脑子一片空白。 这种感觉,就像你开了三年自动挡&am…
AI原生应用助力业务流程增强的实战指南
AI原生应用助力业务流程增强的实战指南 关键词:AI原生应用、业务流程增强、大语言模型(LLM)、智能自动化、人机协作 摘要:本文从企业业务流程的实际痛点出发,系统讲解"AI原生应用"这一新一代技术形态如何从底…