实验三 多态性实验报告.doc_第1页
实验三 多态性实验报告.doc_第2页
实验三 多态性实验报告.doc_第3页
实验三 多态性实验报告.doc_第4页
实验三 多态性实验报告.doc_第5页
免费预览已结束,剩余7页可下载查看

下载本文档

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

文档简介

供参考 浙江理工大学信息学院 实验指导书 实验名称 类的多态性的实现 学时安排 3 实验类别 设计性实验 实验要求 1 人 1 组 学号 姓名 一 实验目的 1 理解重载运算符的意义 2 掌握使用成员函数 友员函数重载运算符的特点 3 掌握重载运算符函数的调用方法 4 掌握动态联编的概念 5 掌握虚函数和纯虚函数的使用方法 二 实验原理介绍 设计性实验 具体原理请见实验内容和步骤 实现对抽象类的继承 通过 operator 函数调用的形式 实现运算符的重载 三 实验设备介绍 软件需求 windows 或 linux 下的 c 编译器 硬件需求 对于硬件方面的要求 建议配置是 Pentium III 450 以上的 CPU 处理器 64MB 以上的内存 200MB 的自由硬盘空间 CD ROM 驱动器 能支 持 24 位真彩色的显示卡 彩色显示器 打印机 四 实验内容 某公司的员工有经理 Manager 技术人员 Technicist 和营销人员 SalsePerson 他们的薪金计算方法如下 经理按月计酬 方法是 基本工资 奖金 技术人员按月计酬 方法是 基 本工资 营销人员按月计酬 方法是 基本工资 销售利润 5 供参考 每类人员都有职工编号 姓名 性别 入职时间 职位 基本工资等数据 各类人员使用统一接口 get pay 计算各类人员的月薪 重载 运算符实现员工 信息的输出 其次 设计一个统计并输出该公司员工当月薪金情况的报表类 Report 该类提供 insert 接口向 Report 类的容器中添加员工信息 并提供 print 接口用于展示以职位为单位的每个员工的职工编号 姓名 性别 入职时间以 及当月该员工的薪酬 并统计出该职位员工薪酬的最高值和最低值 为了提供 更方便的查找功能 请为 Report 类重载 运算符 下标值为职位 能根据职位 信息查找出所有符合该职位的员工 在主函数中对实现的类进行测试 首先 创建各类人员对象 通过 Report 类的 insert 接口向报表中添加这些人员信息 然后通过 Report 类的 print 接口输出当月员工薪酬情况报表 存储员工对象的 容器请选用合适的 STL 容器 五 程序清单 main cpp include class h include int main cout 请输入指定月份 month Report re re insert new Technicist 0001 王华 男 CDate 2 4 2011 技术 9000 re insert new Technicist 0002 李明 女 CDate 4 10 2009 技 术 10000 map bonus bonus 1 1000 bonus 2 2000 bonus 3 3000 供参考 re insert new Manager 0003 朱黎明 男 CDate 11 8 2001 经理 12000 bonus bonus 1 500 bonus 2 1500 bonus 3 2000 re insert new Manager 0004 刘改云 男 CDate 8 7 2003 经理 10000 bonus map sales sales 1 200000 sales 2 100000 sales 3 500000 re insert new SalesPerson 0005 李志武 男 CDate 10 11 2007 销售 5000 sales re print month return 0 class h ifndef CLASS H INCLUDED define CLASS H INCLUDED include include include include include include include date h using namespace std class Employee 供参考 protected string name string ID string sex string job CDate date double basicmoney public Employee string ID string name string sex CDate date string job double basicmoney string getjob return job string getname return name string getID return ID string getsex return sex double getbasicmoney return basicmoney CDate getdate return date virtual double getpay int m 0 class Report private list members list operator string job double min pay list emp list int month double max pay list emp list int month void print list emp list int month public Report 供参考 void insert Employee p void print int n class Manager public Employee private map price public Manager string ID string name string sex CDate date string job double basicmoney map price Employee ID name sex date job basicmoney this price price double getpay int m class Technicist public Employee public Technicist string ID string name string sex CDate date string job double basicmoney Employee ID name sex date job basicmoney double getpay int m class SalesPerson public Employee private map sales public SalesPerson string ID string name string sex CDate date string job double basicmoney map sales Employee ID name sex date job basicmoney 供参考 this sales sales double getpay int m endif fuctions cpp include class h include include using namespace std Employee Employee string ID string name string sex CDate date string job double basicmoney this ID ID this name name this sex sex this date date this basicmoney basicmoney this job job double Manager getpay int m return price m basicmoney list Report operator string job list cp 供参考 list iterator it for it members begin it members end it if it getjob job cp push back it return cp void Report print int month cout 第 month 月职工收入报表 endl cout endl cout 职位 经理 endl cout 工号 t 姓名 t 性别 t 入职时间 t 基本工 资 t 薪酬 endl list emp ls emp ls this 经理 print emp ls month cout 最低薪酬 min pay emp ls month endl cout 最高薪酬 max pay emp ls month endl cout endl cout 职位 销售 endl cout 工号 t 姓名 t 性别 t 入职时间 t 基本工 资 t 薪酬 endl 供参考 emp ls this 销售 print emp ls month cout 最低薪酬 min pay emp ls month endl cout 最高薪酬 max pay emp ls month endl cout endl cout 职位 技术 endl cout 工号 t 姓名 t 性别 t 入职时间 t 基本工 资 t 薪酬 endl emp ls this 技术 print emp ls month cout 最低薪酬 min pay emp ls month endl cout 最高薪酬 max pay emp ls month endl double Report min pay list emp list int month vector pay list iterator it for it emp list begin it emp list end it pay push back it getpay month return min element pay begin pay end double Report max pay list emp list int month vector pay 供参考 list iterator it for it emp list begin it emp list end it pay push back it getpay month return max element pay begin pay end void Report print list emp list int month list iterator it for it emp list begin it emp list end it cout getID t getname t cout getsex t cout getdate format ddd t cout getbasicmoney t t cout getpay month endl void Report insert Employee p members push back p Report Report list iterator it for it members begin it members end it delete it 供参考 double Technicist getpay int m return basicmoney double SalesPerson getpay int m return basic

温馨提示

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

评论

0/150

提交评论