news 2026/4/23 5:10:21

大学有这样几类人员:学生、教师、职员和在职读书的教师。给出这几类人员的类描述。

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
大学有这样几类人员:学生、教师、职员和在职读书的教师。给出这几类人员的类描述。
// 补充必要的头文件(原代码缺失) #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; }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/23 14:13:26

数字图像处理篇---图像高通滤波

核心比喻&#xff1a;图像的“轮廓笔”和“细节放大器”想象你的图像是一幅铅笔画&#xff0c;有粗略的素描轮廓&#xff0c;也有细腻的明暗调子&#xff08;阴影&#xff09;。低通滤波&#xff1a;像用一块软布轻轻涂抹画纸&#xff0c;让细腻的调子&#xff08;阴影&#xf…

作者头像 李华
网站建设 2026/4/23 11:26:48

市场风险的防范策略

市场风险的防范策略 关键词:市场风险、防范策略、风险管理、金融市场、风险评估 摘要:本文聚焦于市场风险的防范策略,旨在为金融从业者、投资者以及相关研究人员提供全面且深入的市场风险管理知识。文章首先介绍了市场风险的背景信息,包括目的、范围、预期读者、文档结构和…

作者头像 李华
网站建设 2026/4/23 15:45:48

元学习框架下的终身推理能力动态调整

元学习框架下的终身推理能力动态调整 关键词:元学习、终身推理能力、动态调整、学习框架、推理算法 摘要:本文围绕元学习框架下的终身推理能力动态调整展开深入探讨。首先介绍了研究的背景、目的、预期读者以及文档结构等内容。接着阐述了核心概念,包括元学习、终身推理能力…

作者头像 李华
网站建设 2026/4/23 12:29:19

提示工程架构师性能建模研究:实用技巧汇总

提示工程架构师性能建模研究&#xff1a;实用技巧汇总 关键词&#xff1a;提示工程、架构师、性能建模、实用技巧、模型评估、优化策略 摘要&#xff1a;本文深入探讨提示工程架构师在性能建模方面的实用技巧。首先介绍提示工程的领域背景与发展历程&#xff0c;明确问题空间…

作者头像 李华