日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

员工(类的多态性实验)

發(fā)布時(shí)間:2024/10/5 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 员工(类的多态性实验) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
浙江理工大學(xué)信息學(xué)院 實(shí)驗(yàn)指導(dǎo)書 實(shí)驗(yàn)名稱:類的多態(tài)性的實(shí)現(xiàn) 學(xué)時(shí)安排:3 實(shí)驗(yàn)類別:設(shè)計(jì)性實(shí)驗(yàn) 實(shí)驗(yàn)要求:1人1組 學(xué)號(hào): 2018329621200 姓名:申屠志剛  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄

一、實(shí)驗(yàn)?zāi)康?br /> 1.理解重載運(yùn)算符的意義。
2.掌握使用成員函數(shù)、友員函數(shù)重載運(yùn)算符的特點(diǎn)。
3.掌握重載運(yùn)算符函數(shù)的調(diào)用方法。
4.掌握動(dòng)態(tài)聯(lián)編的概念。
5.掌握虛函數(shù)和純虛函數(shù)的使用方法。
二、實(shí)驗(yàn)原理介紹
設(shè)計(jì)性實(shí)驗(yàn)
具體原理請見實(shí)驗(yàn)內(nèi)容和步驟
實(shí)現(xiàn)對抽象類的繼承,通過operator函數(shù)調(diào)用的形式,實(shí)現(xiàn)運(yùn)算符的重載
三、實(shí)驗(yàn)設(shè)備介紹
軟件需求: windows或linux下的c++編譯器
硬件需求: 對于硬件方面的要求,建議配置是Pentium III 450以上的CPU處理器,64MB以上的內(nèi)存,200MB的自由硬盤空間、CD-ROM驅(qū)動(dòng)器、能支持24位真彩色的顯示卡、彩色顯示器、打印機(jī)。
四、實(shí)驗(yàn)內(nèi)容
某公司的員工有經(jīng)理Manager、技術(shù)人員Technicist和營銷人員SalsePerson,他們的薪金計(jì)算方法如下:
經(jīng)理按月計(jì)酬,方法是:基本工資+獎(jiǎng)金;技術(shù)人員按月計(jì)酬,方法是:基本工資;營銷人員按月計(jì)酬,方法是:基本工資+銷售利潤*5%。
每類人員都有職工編號(hào)、姓名、性別、入職時(shí)間、職位、基本工資等數(shù)據(jù),其中為入職時(shí)間定義CDate類,并為該類重載運(yùn)算符<<,實(shí)現(xiàn)入職時(shí)間的輸出;各類人員使用統(tǒng)一接口get_pay()計(jì)算各類人員的月薪。其次,設(shè)計(jì)一個(gè)統(tǒng)計(jì)并輸出該公司每個(gè)人員某幾個(gè)月薪金情況的報(bào)表類Report,該類提供insert接口向Report類的容器中添加員工信息,并提供print接口用于輸出每個(gè)員工的職工編號(hào)、姓名、性別、入職時(shí)間、職位和在設(shè)定的月份時(shí)間段中該員工的薪酬總額。為了方便實(shí)現(xiàn)查找功能,為Report類重載[]運(yùn)算符的功能,下標(biāo)值為職位,能根據(jù)職位信息查找出所有符合該職位的員工,并重載print接口,輸出查找出的員工信息,信息包括職工編號(hào)、姓名、性別、入職時(shí)間、職位、基本工資。在主函數(shù)中對實(shí)現(xiàn)的類進(jìn)行測試,首先,創(chuàng)建各類人員對象,通過Report類的insert接口向報(bào)表中添加這些人員信息,然后通過Report類的print接口輸出報(bào)表。其次測試報(bào)表的查找功能,輸入要查找的員工職位信息,通過Report類的print接口輸出查找到的員工基本信息報(bào)表。
五、注意事項(xiàng)和要求
要求學(xué)生要提前準(zhǔn)備實(shí)驗(yàn)的內(nèi)容
實(shí)驗(yàn)完成后要求寫出實(shí)驗(yàn)報(bào)告
六、參考書目
【C++ Prime題解】侯捷譯 華中科技大學(xué)出版社
【C++程序設(shè)計(jì)與應(yīng)用】 張耀仁著 華中科技大學(xué)出版社

浙江理工大學(xué)信息學(xué)院 實(shí)驗(yàn)指導(dǎo)書 實(shí)驗(yàn)名稱:類的多態(tài)性的實(shí)現(xiàn) 學(xué)時(shí)安排:3 實(shí)驗(yàn)類別:設(shè)計(jì)性實(shí)驗(yàn) 實(shí)驗(yàn)要求:1人1組 學(xué)號(hào): 2018329621200 姓名:申屠志剛  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄

一、實(shí)驗(yàn)?zāi)康?br /> 1.理解重載運(yùn)算符的意義。
2.掌握使用成員函數(shù)、友員函數(shù)重載運(yùn)算符的特點(diǎn)。
3.掌握重載運(yùn)算符函數(shù)的調(diào)用方法。
4.掌握動(dòng)態(tài)聯(lián)編的概念。
5.掌握虛函數(shù)和純虛函數(shù)的使用方法。
二、實(shí)驗(yàn)原理介紹
設(shè)計(jì)性實(shí)驗(yàn)
具體原理請見實(shí)驗(yàn)內(nèi)容和步驟
實(shí)現(xiàn)對抽象類的繼承,通過operator函數(shù)調(diào)用的形式,實(shí)現(xiàn)運(yùn)算符的重載
三、實(shí)驗(yàn)設(shè)備介紹
軟件需求: windows或linux下的c++編譯器
硬件需求: 對于硬件方面的要求,建議配置是Pentium III 450以上的CPU處理器,64MB以上的內(nèi)存,200MB的自由硬盤空間、CD-ROM驅(qū)動(dòng)器、能支持24位真彩色的顯示卡、彩色顯示器、打印機(jī)。
四、實(shí)驗(yàn)內(nèi)容
某公司的員工有經(jīng)理Manager、技術(shù)人員Technicist和營銷人員SalsePerson,他們的薪金計(jì)算方法如下:
經(jīng)理按月計(jì)酬,方法是:基本工資+獎(jiǎng)金;技術(shù)人員按月計(jì)酬,方法是:基本工資;營銷人員按月計(jì)酬,方法是:基本工資+銷售利潤*5%。
每類人員都有職工編號(hào)、姓名、性別、入職時(shí)間、職位、基本工資等數(shù)據(jù);各類人員使用統(tǒng)一接口get_pay()計(jì)算各類人員的月薪,重載<<運(yùn)算符實(shí)現(xiàn)員工信息的輸出。其次,設(shè)計(jì)一個(gè)統(tǒng)計(jì)并輸出該公司員工當(dāng)月薪金情況的報(bào)表類Report,該類提供insert接口向Report類的容器中添加員工信息,并提供print接口用于展示以職位為單位的每個(gè)員工的職工編號(hào)、姓名、性別、入職時(shí)間以及當(dāng)月該員工的薪酬,并統(tǒng)計(jì)出該職位員工薪酬的最高值和最低值。為了提供更方便的查找功能,請為Report類重載[]運(yùn)算符,下標(biāo)值為職位,能根據(jù)職位信息查找出所有符合該職位的員工。在主函數(shù)中對實(shí)現(xiàn)的類進(jìn)行測試,首先,創(chuàng)建各類人員對象,通過Report類的insert接口向報(bào)表中添加這些人員信息,然后通過Report類的print接口輸出當(dāng)月員工薪酬情況報(bào)表。存儲(chǔ)員工對象的容器請選用合適的STL容器。
五 程序清單
date.h

#pragma once #include <iostream> #include<cstdlib> #include<string> #include<cstdio> #include<ctime> using namespace std; class CDate{int d,m,y;static const string df_s;static const string df_l;static CDate *default_date; public:CDate(int dd,int mm,int yy);CDate();void add_year(int n);void add_month(int n);void add_day(int n);string format(string df);int get_day() const;int get_month() const;int get_year() const;static void set_default(int,int,int);friend ostream& operator<<(ostream &os,CDate d); };

date.cpp

#include "date.h" CDate::CDate(int dd, int mm, int yy) //初始化 {if((mm>=1 && mm<=12) && (dd>=1 && dd<=31)){m = mm; d = dd; y = yy;}else {m = 0; d = 0; y = 0;cout << "the date created is wrong" << endl;} } CDate::CDate() //初始化 {if(default_date != 0){d = default_date -> d;m = default_date -> m;y = default_date -> y;}else{time_t now;time(&now);struct tm *t_now;t_now = localtime(&now);y = t_now -> tm_year + 1900;m = t_now -> tm_mon + 1;d = t_now -> tm_mday;} } void CDate::add_year(int n) //加n年 {y += n; } void CDate::add_month(int n) //加n月 {m += n; } void CDate::add_day(int n) //加n天 {d += n; } string CDate::format(string df) {char c_df[20];if(df == df_s){sprintf(c_df, "%d-%d-%d", y, m, d);return string(c_df);}if(df == df_l){sprintf(c_df, "%d年%d月%d日", y, m, d);return string(c_df);}return string(""); } int CDate::get_year() const {return y; } int CDate::get_month() const {return m; } int CDate::get_day() const {return d; } CDate *CDate::default_date = 0; const string CDate::df_s = "ddd"; const string CDate::df_l = "DDD"; void CDate::set_default(int d, int m, int y){CDate::default_date = new CDate(d,m,y); } ostream& operator<<(ostream &os,CDate d) {os<<d.format("DDD");return os; }

Employee.h

#pragma once #include<string> #include<map> #include<iostream> #include <iomanip> #include"date.h" using namespace std; class Employee { protected:string name,id;int gender;CDate enroll_date;string job;int salary; public:Employee(string ID,string Name,int Gender,CDate Enroll_date,string Job,int Salary);void set_salary(int salary){this->salary = salary;}void set_job(string job){this->job = job;}void set_enroll(CDate enroll){this->enroll_date = enroll;}string get_id(){return id;}string get_name(){return name;}CDate get_enroll(){return enroll_date;}int get_gender(){return gender;}string get_job(){return job;}int get_salary(){return salary;}virtual double get_pay(int m) = 0;friend ostream &operator<<(ostream &output,const Employee &a1); }; class Manager:public Employee{map<int,int> bonus; public:Manager(string id,string name,int gender,CDate enroll,string job,int salary);Manager(string id,string name,int gender,CDate enroll,string job,int salary,map<int,int> bonus);void set_bonus(map<int,int> bonus);virtual double get_pay(int m); }; class Technicist:public Employee{ public:Technicist(string id,string name,int gender,CDate enroll,string job,int salary);virtual double get_pay(int m); }; class SalesPerson:public Employee{ private:map<int,int> sales; public:SalesPerson(string id,string name,int gender,CDate enroll,string job,int salary);SalesPerson(string id,string name,int gender,CDate enroll,string job,int salary,map<int,int> sales);void set_sales(map<int,int> sales);virtual double get_pay(int m); };

Employee.cpp

#include<iostream> #include "Employee.h" using namespace std;ostream &operator<<(ostream &output,const Employee &a) {output<<a.id<<"\t"<<a.name<<"\t"<<(a.gender?"男":"女")<<"\t"<<a.enroll_date<<"\t"<<a.job<<"\t"<<a.salary;return output; }Employee::Employee(string ID,string Name,int Gender,CDate Enroll_date,string Job,int Salary){id=ID;name=Name;gender=Gender;enroll_date=Enroll_date;salary=Salary;job=Job; } Manager::Manager(string id,string name,int gender,CDate enroll,string job,int salary):Employee(id,name,gender,enroll,job,salary){} Manager::Manager(string id,string name,int gender,CDate enroll,string job,int salary,map<int,int> bonus):Employee(id,name,gender,enroll,job,salary),bonus(bonus){} double Manager::get_pay(int m){return bonus[m]+get_salary();} Technicist::Technicist(string id,string name,int gender,CDate enroll,string job,int salary):Employee(id,name,gender,enroll,job,salary){} double Technicist::get_pay(int m){return get_salary();} SalesPerson::SalesPerson(string id,string name,int gender,CDate enroll,string job,int salary):Employee(id,name,gender,enroll,job,salary){} SalesPerson::SalesPerson(string id,string name,int gender,CDate enroll,string job,int salary,map<int,int> sales):Employee(id,name,gender,enroll,job,salary),sales(sales){} double SalesPerson::get_pay(int m){return sales[m]*0.05+get_salary();}

Report.h

#include"Employee.h" #include<vector> #include<list> #include<iostream> #include<algorithm> using namespace std; class Report { private:vector<Employee*> members;list<Employee*> operator[](string job);double min_pay(list<Employee*> emp_list, int month);double max_pay(list<Employee*> emp_list, int month);void print(list<Employee*> emp_list,int month); public:~Report();void insert(Employee* member);void print(int rp_mon); };

Report.cpp

#include "Report.h" Report::~Report(){} list<Employee*> Report::operator[](string job){list<Employee*> L;for(vector<Employee*>::iterator iter1=members.begin();iter1!=members.end();iter1++){if((*iter1)->get_job()==job){L.push_back(*iter1);}}return L; } double Report::min_pay(list<Employee*> emp_list, int month){list<double>Payment;for(list<Employee*>::iterator iter3=emp_list.begin();iter3!=emp_list.end();iter3++){Payment.push_back((*iter3)->get_pay(month));}return *min_element(Payment.begin(),Payment.end()); } double Report::max_pay(list<Employee*> emp_list, int month){list<double>Payment;for(list<Employee*>::iterator iter3=emp_list.begin();iter3!=emp_list.end();iter3++){Payment.push_back((*iter3)->get_pay(month));}return *max_element(Payment.begin(),Payment.end()); } void Report::print(list<Employee*> emp_list,int month){for(list<Employee*>::iterator iter2=emp_list.begin();iter2!=emp_list.end();iter2++){cout<<(*(*iter2))<<"\t"<<(*iter2)->get_pay(month)<<endl;} }void Report::insert(Employee* member){members.push_back(member); } void Report::print(int rp_mon){cout<<" 第"<<rp_mon<<"月職工收入報(bào)表 "<<endl;list<Employee*>empl;string Position[3]={"經(jīng)理","技術(shù)","銷售"};for(int i=0;i<3;i++){cout<<"------------------------------------------------------------------------"<<endl;cout<<"職位:"<<Position[i]<<endl;cout<<"工號(hào)\t"<<"姓名\t"<<"性別\t"<<"入職時(shí)間\t"<<"職位\t"<<"基本工資\t"<<"獎(jiǎng)金"<<endl;empl=(*this)[Position[i]];print(empl,rp_mon);cout<<"Max payment: "<<max_pay(empl,rp_mon)<<endl;cout<<"Min payment: "<<min_pay(empl,rp_mon)<<endl<<endl;} }

main.cpp

/* *@Author: STZG *@Language: C++ */ #include<iostream> #include "employee.h" #include "report.h" #include "date.h" using namespace std; int main() {Report AA;AA.insert(new Manager("001","Tom",1,CDate(11,8,2001),"經(jīng)理",2000,map<int,int>{{1,1000},{2,2000},{3,3000},{4,3000},{5,2500},{6,4000},{7,7000},{8,8000},{9,3000},{10,1050},{11,10000},{12,6000}}));AA.insert(new Manager("002","Ann",0,CDate(23,5,2013),"經(jīng)理",3000,map<int,int>{{1,1000},{2,2000},{3,3000},{4,3000},{5,2500},{6,4000},{7,7000},{8,8000},{9,3000},{10,1050},{11,10000},{12,6000}}));AA.insert(new Manager("003","Jim",1,CDate(16,7,1998),"經(jīng)理",3000,map<int,int>{{1,1000},{2,2000},{3,3000},{4,3000},{5,2500},{6,4000},{7,7000},{8,8000},{9,3000},{10,1050},{11,10000},{12,6000}}));AA.insert(new Technicist("004","David",0,CDate(14,12,2009),"技術(shù)",2000));AA.insert(new Technicist("005","Tina",1,CDate(26,8,2015),"技術(shù)",1500));AA.insert(new Technicist("006","John",1,CDate(18,1,1999),"技術(shù)",3000));AA.insert(new SalesPerson("007","Helen",0,CDate(4,2,2000),"銷售",2000,map<int,int>{{1,1000},{2,8000},{3,1000},{4,9000},{5,1000},{6,1000},{7,1000},{8,1000},{9,1000},{10,2000},{11,1000},{12,1000}}));AA.insert(new SalesPerson("008","Lily",0,CDate(30,11,2007),"銷售",1000,map<int,int>{{1,1000},{2,2000},{3,3000},{4,3000},{5,2500},{6,4000},{7,7000},{8,8000},{9,3000},{10,1050},{11,10000},{12,6000}}));AA.insert(new SalesPerson("009","Tony",1,CDate(1,8,2013),"銷售",1500,map<int,int>{{1,1000},{2,1000},{3,3000},{4,1000},{5,1000},{6,1000},{7,1000},{8,1000},{9,1000},{10,1000},{11,1000},{12,1000}}));int month;cout<<"請輸入生成報(bào)表的月份"<<endl;cin>>month;AA.print(month);//cout << "Hello world!" << endlreturn 0; }

六 運(yùn)行結(jié)果

七 實(shí)驗(yàn)心得
1.理解重載運(yùn)算符的意義。
2.掌握使用成員函數(shù)、友員函數(shù)重載運(yùn)算符的特點(diǎn)。
3.掌握重載運(yùn)算符函數(shù)的調(diào)用方法。
4.掌握動(dòng)態(tài)聯(lián)編的概念。
5.掌握虛函數(shù)和純虛函數(shù)的使用方法。

總結(jié)

以上是生活随笔為你收集整理的员工(类的多态性实验)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。