C++第7次实验报告_第1页
C++第7次实验报告_第2页
C++第7次实验报告_第3页
C++第7次实验报告_第4页
C++第7次实验报告_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C 语言程序设计语言程序设计 课程实验报告 第课程实验报告 第 7 次 次 学学 院 数学与计算机学院院 数学与计算机学院 姓姓 名 张元杰名 张元杰 学学 号 号 201510804033 专专 业 软件工程业 软件工程 班班 级 级 1 班班 同同 组组 人 人 实验地点 实验地点 6A 2 实验时间 实验时间 指导教师 指导教师 实验名称 实验名称 继承与派生继承与派生 二二 所使用的开发工具及环境 所使用的开发工具及环境 硬件硬件 PC 机一台机一台 实验目的 实验目的 1 理解继承和派生的概念 2 理解继承在面向对象程序设计中的重要作用 3 掌握通过继承派生出一个新类的方法 4 进一步学习简单面向对象程序的编写 实验内容 实验内容 1 教师干部类 50 分 设计一个基类 Person 类 再派生出教师类 Teacher 干部类 Cadre 再采用多重继 承派生出新类 Teacher Cadre 要求如下 1 Person 类包含 姓名 年龄 性别 地址 电话等 在 Teacher 类中新增加 title 职称 在 Cadre 类中新增加 post 职务 在 Teacher Cadre 中新增加 wages 工资 成员 2 Person 类 Teacher 类 Cadre 类都包含 display 函数 分别输出本类中的成员 信息 3 在 Teacher 类 Cadre 类中的姓名 年龄 性别 地址 电话等数据成员使用相 同名字 在派生类中引用这些数据成员时 采用指定作用域的方式 4 在派生类 Teacher Cadre 的成员函数 Show 中调用 Teacher 类中的 display 函数 输出姓名 年龄 性别 地址 电话 职称 另外同时再输出其 他成员变量 5 使用对象数组保存输入的对象 2 小型公司人员管理 某小型公司有四类人员 总经理 技术人员 销售经理 推销员 设计一个基类 employee 派生出 manager 总经理 technician 技术人员 salesmanager 销售 经理 saleman 推销员 销售经理既是经理又是销售人员 兼具两类人员的特点 因此同时继承 manager 和 salesman 两个类 50 分 1 类定义 employee 类 基本信息 编号 姓名 性别 出生日期 职位 薪水等 出生日期使用自定义的 Date 日期 类 其中 基本信息为 private 属性 成员函数为 public 属性 多个构造 函数 缺省构造函数 带参数的构造函数 带默认参数的构造函数 可以从外部访问类 成员函数 Date 类 成员变量 年 月 日 成员函数 SetYear int year SetMonth int month SetDay int day GetYear GetMonth GetDay 派生类 technician 新增属性 工作时间 派生类 saleman 新增属性 销售额 所属部门 2 实现人员信息的录入与显示 3 计算并显示个人月薪 月薪计算办法 总经理拿固定月薪 8000 元 技术人员按每小时 25 元领取月薪 推销 员的月薪按当月销售额的 4 提成 销售经理固定月薪 5000 元加所管辖部门当月销售 总额的 5 实验提示 在基类中 除了定义构造函数和析构函数 还应统一定义对各类人员信息应有的操作 规范类族中各派生类的基本行为 但是各类人员的月薪计算方法不同 不能在基类 employee 中统一确定计算方法 各类人员信息的显示内容不同 同样不能在基类 employee 中统一确定显示方法 在基类中实现上述功能的函数体应为空 在派生类中根 据同名覆盖原则定义各自的同名函数实现具体功能 将基类 employee 分成两个独立文档 employee h 类声明头文件 和 employy cpp 类实现文件 职位 的类型设定为 int 结果与分析 结果与分析 Sy7 1 include include using namespace std class Person public Person Person string na int ag string se string ad string te name na age ag sex se addr ad tel te void display private string name int age string sex string addr string tel class Teacher public Person public Teacher string na int ag string se string ad string te string ti Person na ag se ad te title ti void display private string title 职称 class Cadre public Person public Cadre string na int ag string se string ad string te string po Person na ag se ad te post po void display string Post return post private string post 职务 class Teacher Cadre public Teacher Cadre public Teacher Cadre string na int ag string se string ad string te string ti string po double wa Teacher na ag se ad te ti Cadre na ag se ad te po wages wa void show private double wages void Person display cout Name name endl cout Age age endl cout Sex sex endl cout Address addr endl cout Tel tel endl void Teacher display Person display cout Title title endl void Cadre display Person display cout Post post endl void Teacher Cadre show Teacher display cout Post Post endl cout Wages wages endl endl int main Teacher Cadre tc 3 Teacher Cadre 张三 33 男 成都 1304233899 教授 教务处 主任 7999 Teacher Cadre 李思 25 女 重庆讲师 助 理 5677 Teacher Cadre 王武 27 男 广州副教授 讲师 6299 for int i 0 i 3 i tc i show system pause return 0 Sy7 2 include include using namespace std class Date 时间类 public Date int ye 0 int mo 0 int da 0 year ye month mo day da void SetYear int year year year void SetMonth int month month month void SetDay int day day day int GetYear return year int GetMonth return month int GetDay return day private int year int month int day class Employee 雇员类 public Employee Employee int nu string na string se int ye int mo int da string ti num nu name na sex se birthday ye mo da title ti void Setwages double wa wages wa void display Date birthday private double wages int num string name string sex string title class Manager virtual public Employee 经理类 public Manager Manager int nu string na string se int ye int mo int da string ti Employee nu na se ye mo da ti Setwages 8000 void display class Technician public Employee 技术人员类 public Technician int nu string na string se int ye int mo int da string ti double wo Employee nu na se ye mo da ti WorkTime wo Setwages WorkTime 25 void display private double WorkTime class Saleman virtual public Employee 销售员类 public Saleman int nu string na string se int ye int mo int da string ti double sa string de Employee nu na se ye mo da ti department de sale sa Setwages sale 0 04 double Getsale return sale void display private double sale string department class Salesmanager public Saleman Manager 销售经理类 public Salesmanager int nu string na string se int ye int mo int da string ti double sa string de Saleman nu na se ye mo da ti sa de Manager nu na se ye mo da ti Employee nu na se ye mo da ti Setwages 5000 Getsale 0 005 void display int main Manager m1 101 张三 男 1987 4 3 经理 m1 display cout endl Technician te1 301 李嗣 男 1988 4 23 技术人员 200 te1 display cout endl Saleman sm1 201 王武 男 1990 6 3 销售员 20000 副食部 sm1 display cout endl Saleman sm2 202 陈琪 女 1992 12 17 销售员 40000 副食部 sm2 display cout endl Salesmanager sma1 210 赵柳 女 1986 4 29 销售经理 60000 副食部 sma1 display system pause return 0 void Employee display 基本信息 编号 姓名 性别 出生日期 职位 薪水等 cout 编号 num endl cout 姓名 name endl cout 性别 sex endl cout 出生日期 birthday GetYear birthday GetMonth birthday GetDay e

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论