
免费预览已结束,剩余11页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
浙江理工大学信息学院 实验指导书 实验名称:类的多态性的实现 学时安排: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()计算各类人员的月薪,重载 int main() coutmonth; Report re; re.insert(new Technicist(“0001“,“王华“,“男“,CDate(2,4,2011),“技术 “,9000); re.insert(new Technicist(“0002“,“李明“,“女“,CDate(4,10,2009),“技 术“,10000); map bonus; bonus1 = 1000; bonus2 = 2000; bonus3 = 3000; re.insert(new Manager(“0003“,“朱黎明“,“男“,CDate(11,8,2001),“经理 “,12000,bonus); bonus1 = 500; bonus2 = 1500; bonus3 = 2000; re.insert(new Manager(“0004“,“刘改云“,“男“,CDate(8,7,2003),“经理 “,10000,bonus); map sales; sales1 = 200000; sales2 = 100000; sales3 = 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 pricem+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 emp_ls; emp_ls = (*this)“经理“; print(emp_ls,month); cout 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 +) coutgetID()getname()getsex()getdate().format(“ddd“)getbasicmoney()getpay(month) :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 basicmoney + salesm * 0.05; /date.h /增加友元
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论