1、用多态性实现工资发放系统 源代码#ifndef HEADER_KESHE1#define HEADER_KESHE1class Birthdate unsigned year,month;public: Birthdate(unsigned=1900,unsigned=01); void SetYear(unsigned); void SetMonth(unsigned); unsigned GetYear() const; unsigned GetMonth() const; friend ostream& operator(ostream& out, Birthdate& b) retur
2、n outsetw(6) b.year / setw(2) setfill(0)(istream& in,Birthdate& b) string buf; in buf; b.SetYear(atoi(buf.substr(0,4).c_str(); b.SetMonth(atoi(buf.substr(5,2).c_str(); return in; friend ofstream& operator(ofstream& fout, Birthdate& b) fout setfill( )b.GetYear() /; fout setw(2)setfill(0)b.GetMonth()(
3、ifstream& fin,Birthdate& b) string buf; fin buf; b.SetYear(atoi(buf.substr(0,4).c_str(); b.SetMonth(atoi(buf.substr(5,2).c_str(); return fin; ;#endif#include#include#include#includeusing namespace std;#includekeshe1.hBirthdate:Birthdate(unsigned y,unsigned m) year=y; month=m;void Birthdate:SetYear(u
4、nsigned y) year=y;void Birthdate:SetMonth(unsigned m) month=m;unsigned Birthdate:GetYear()const return year;unsigned Birthdate:GetMonth()const return month;#ifndef HEADER_KESHE2#define HEADER_KESHE2#includekeshe1.hclass Employee unsigned ID; string name; Birthdate bir; string type; bool reward; bool
5、 draw; public: Employee(unsigned i,string,Birthdate,string); Employee(Employee& ); void SetName(string); void SetBirth(unsigned,unsigned); void SetBirth(Birthdate b); void SetType(string); void SetReward(bool); void SetDraw(bool); void SetID(unsigned); unsigned GetId() const; string GetName() const;
6、 Birthdate GetBirthday() const; string GetType() const; bool GetReward(unsigned) const; bool GetDraw() const; virtual double Pay() const return 0; virtual void Display() ; virtual void writeoffile(ofstream& fout) ; ;#endif#include#include#include#includeusing namespace std;#includekeshe2.hEmployee:E
7、mployee(unsigned i,string n,Birthdate b,string t):bir(b) ID=i; name=n; type=t; reward=0; draw=0;Employee:Employee(Employee& e) ID=e.ID; name=e.name; type=e.type; reward=e.reward; draw=e.draw; bir=e.bir;void Employee:SetName(string n) name=n;void Employee:SetBirth(unsigned y,unsigned m) bir.SetYear(y
8、); bir.SetMonth(m);void Employee:SetBirth(Birthdate b) bir=b;void Employee:SetType(string t) type=t;void Employee:SetReward(bool r) reward=r;void Employee:SetDraw(bool d) draw=d;void Employee:SetID(unsigned id) ID=id;unsigned Employee:GetId()const return ID;string Employee:GetName()const return name
9、;Birthdate Employee:GetBirthday()const return bir;string Employee:GetType()const return type;bool Employee:GetReward(unsigned m)const if(m=bir.GetMonth() return 1; return reward;bool Employee:GetDraw()const return draw;void Employee:Display() coutsetfill(0)setw(6)ID; coutsetfill( )setw(6)namesetw(7)
10、bir.GetYear()/setw(2)bir.GetMonth()setw(6)typesetw(10);void Employee:writeoffile(ofstream& fout) foutsetfill(0)setw(6)ID ; foutsetfill( )namesetw(8)bir.GetYear() bir.GetMonth()setw(8)typesetw(8)drawsetw(8);#ifndef HEADER_KESHE3#define HEADER_KESHE3#includekeshe2.hclass SalariedEmployee:virtual publi
11、c Employee int leaveday; double salary; public: SalariedEmployee(unsigned ,string,Birthdate,string,int,double); SalariedEmployee(Employee& ,int ,double); void SetLeaveDay(int); void SetSalary(double); int GetLeaveDay() const; double GetSalary() const; virtual double Pay() const; virtual void Display
12、() ; virtual void writeoffile(ofstream& fout) ; ;#endif#include#include#include#include#includeusing namespace std;#includekeshe3.hSalariedEmployee:SalariedEmployee(unsigned i,string n,Birthdate b,string t,int l=0,double s=3000):Employee(i,n,b,t) leaveday=l; salary=s;SalariedEmployee:SalariedEmploye
13、e(Employee& e,int l,double s ):Employee(e) leaveday=l; salary=s;void SalariedEmployee:SetLeaveDay(int l) leaveday=l;void SalariedEmployee:SetSalary(double s) salary=s;int SalariedEmployee:GetLeaveDay()const return leaveday;double SalariedEmployee:GetSalary()const return salary;double SalariedEmploye
14、e:Pay()const unsigned m; SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m) return (salary+30*leaveday+200); else return salary+30*leaveday;void SalariedEmployee:Display() unsigned m; cout*固定薪金职员*endl; coutsetw(6)编号setw(6)姓名setw(10)出生年月setw(6)工种setw(10)奖励薪金setw(10); cout固定月薪setw(10)请假
15、天数setw(6)应扣setw(10)实发工资setw(10)是否领取endl; Employee:Display(); SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m) cout200; else cout0; coutsetw(10)salarysetw(10)leavedaysetw(6)leaveday*30setw(10)Pay()setw(10); if(GetDraw() cout是endl; else cout否endl;void SalariedEmployee:writeoffile(ofst
16、ream& fout) foutG setw(8); Employee:writeoffile(fout); foutsetw(8)salarysetw(8)leavedayendl;#ifndef HEADER_KESHE4#define HEADER_KESHE4#includekeshe3.hclass HourlyEmployee:public Employee int hour; double sperhour; public: HourlyEmployee(unsigned ,string,Birthdate,string,int,double); HourlyEmployee(E
17、mployee&,int ,double ); void SetHour(int); void SetSperHour(double); int GetHour() const; double GetSperHour() const; virtual double Pay() const; virtual void Display() ; virtual void writeoffile(ofstream& fout); ;#endif#include#include#include#include#includeusing namespace std;#includekeshe4.hHour
18、lyEmployee:HourlyEmployee(unsigned i,string n,Birthdate b,string t,int h,double s):Employee(i,n,b,t) hour=h; sperhour=s;HourlyEmployee:HourlyEmployee(Employee& e,int h,double s):Employee(e) hour=h; sperhour=s;void HourlyEmployee:SetHour(int h) hour=h;void HourlyEmployee:SetSperHour(double s) sperhou
19、r=s;int HourlyEmployee:GetHour()const return hour;double HourlyEmployee:GetSperHour()const return sperhour;double HourlyEmployee:Pay()const unsigned m; SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m) return (sperhour*160+sperhour*1.5*(hour-160)+200); else return (sperhour*160+sperh
20、our*1.5*(hour-160);void HourlyEmployee:Display() unsigned m; cout*计时职员*endl; coutsetw(6)编号setw(6)姓名setw(10)出生年月setw(6)工种setw(10)奖励薪金setw(10); cout工作时长setw(6)时薪setw(10)加班时长setw(10)实发工资setw(10)是否领取endl; Employee:Display(); SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m) cout200; else
21、 cout0; coutsetw(10)hoursetw(6)sperhoursetw(10)hour-160setw(10)Pay()setw(10); if(GetDraw() cout是endl; else cout否endl;void HourlyEmployee:writeoffile(ofstream& fout) foutJ setw(8); Employee:writeoffile(fout); foutsetw(8)hoursetw(8)sperhourendl;#ifndef HEADER_KESHE5#define HEADER_KESHE5#includekeshe4.
22、hclass CommisionEmployee:virtual public Employee double sale; double ratio; public: CommisionEmployee(unsigned ,string,Birthdate,string,double,double); CommisionEmployee(Employee&,double,double); void SetSale(double); void SetRatio(double); double GetSale() const; double GetRatio() const; virtual do
23、uble Pay() const; virtual void Display() ; virtual void writeoffile(ofstream& fout) ; ;#endif#include#include#include#include#includeusing namespace std;#includekeshe5.hCommisionEmployee:CommisionEmployee(unsigned i,string n,Birthdate b,string t,double s,double a):Employee(i,n,b,t) sale=s; ratio=a;C
24、ommisionEmployee:CommisionEmployee(Employee& e,double s,double a):Employee(e) sale=s; ratio=a;void CommisionEmployee:SetSale(double s) sale=s;void CommisionEmployee:SetRatio(double a) ratio=a;double CommisionEmployee:GetSale()const return sale;double CommisionEmployee:GetRatio()const return ratio;do
25、uble CommisionEmployee:Pay()const unsigned m; SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(sale30000) if(GetReward(m) return (sale*ratio-(30000-sale)*(2.0/1000)+200); else return (sale*ratio-(30000-sale)*(2.0/1000); else if(GetReward(m) return (sale*ratio+200); else return sale*ratio; void C
26、ommisionEmployee:Display() unsigned m; cout*普通销售员*endl; coutsetw(6)编号setw(6)姓名setw(10)出生年月setw(6)工种setw(10)奖励薪金setw(8); cout销售额setw(10)提成比例setw(8)应扣setw(10)实发工资setw(10)是否领取endl; Employee:Display(); SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m) cout200; else cout0; coutsetw(8)salesetw(10)ratiosetw(8); if(sale30000) cout(30000-sale)*(2.0/1000)setw(10)Pay()setw(4); else cout0setw(10)Pay()setw(4); if(GetDraw() cout是endl; else cout否
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1