用多态性实现工资发放系统 源代码.docx
《用多态性实现工资发放系统 源代码.docx》由会员分享,可在线阅读,更多相关《用多态性实现工资发放系统 源代码.docx(48页珍藏版)》请在冰豆网上搜索。
用多态性实现工资发放系统源代码
#ifndefHEADER_KESHE1
#defineHEADER_KESHE1
classBirthdate
{
unsignedyear,month;
public:
Birthdate(unsigned=1900,unsigned=01);
voidSetYear(unsigned);
voidSetMonth(unsigned);
unsignedGetYear()const;
unsignedGetMonth()const;
friendostream&operator<<(ostream&out,Birthdate&b){
returnout<(2)<}
friendistream&operator>>(istream&in,Birthdate&b){
stringbuf;
in>>buf;
b.SetYear(atoi(buf.substr(0,4).c_str()));
b.SetMonth(atoi(buf.substr(5,2).c_str()));
returnin;
}
friendofstream&operator<<(ofstream&fout,Birthdate&b){
fout<fout<(2)<returnfout;
}
friendifstream&operator>>(ifstream&fin,Birthdate&b){
stringbuf;
fin>>buf;
b.SetYear(atoi(buf.substr(0,4).c_str()));
b.SetMonth(atoi(buf.substr(5,2).c_str()));
returnfin;
}
};
#endif
#include
#include
#include
#include
usingnamespacestd;
#include"keshe1.h"
Birthdate:
:
Birthdate(unsignedy,unsignedm){
year=y;
month=m;
}
voidBirthdate:
:
SetYear(unsignedy)
{
year=y;
}
voidBirthdate:
:
SetMonth(unsignedm){
month=m;
}
unsignedBirthdate:
:
GetYear()const{
returnyear;
}
unsignedBirthdate:
:
GetMonth()const{
returnmonth;
}
#ifndefHEADER_KESHE2
#defineHEADER_KESHE2
#include"keshe1.h"
classEmployee{
unsignedID;
stringname;
Birthdatebir;
stringtype;
boolreward;
booldraw;
public:
Employee(unsignedi,string,Birthdate,string);
Employee(Employee&);
voidSetName(string);
voidSetBirth(unsigned,unsigned);
voidSetBirth(Birthdateb);
voidSetType(string);
voidSetReward(bool);
voidSetDraw(bool);
voidSetID(unsigned);
unsignedGetId()const;
stringGetName()const;
BirthdateGetBirthday()const;
stringGetType()const;
boolGetReward(unsigned)const;
boolGetDraw()const;
virtualdoublePay()const{return0;};
virtualvoidDisplay();
virtualvoidwriteoffile(ofstream&fout);
};
#endif
#include
#include
#include
#include
usingnamespacestd;
#include"keshe2.h"
Employee:
:
Employee(unsignedi,stringn,Birthdateb,stringt):
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;
}
voidEmployee:
:
SetName(stringn){
name=n;
}
voidEmployee:
:
SetBirth(unsignedy,unsignedm){
bir.SetYear(y);
bir.SetMonth(m);
}
voidEmployee:
:
SetBirth(Birthdateb){
bir=b;
}
voidEmployee:
:
SetType(stringt){
type=t;
}
voidEmployee:
:
SetReward(boolr){
reward=r;
}
voidEmployee:
:
SetDraw(boold){
draw=d;
}
voidEmployee:
:
SetID(unsignedid){
ID=id;
}
unsignedEmployee:
:
GetId()const{
returnID;
}
stringEmployee:
:
GetName()const{
returnname;
}
BirthdateEmployee:
:
GetBirthday()const{
returnbir;
}
stringEmployee:
:
GetType()const{
returntype;
}
boolEmployee:
:
GetReward(unsignedm)const{
if(m==bir.GetMonth())
return1;
returnreward;
}
boolEmployee:
:
GetDraw()const{
returndraw;
}
voidEmployee:
:
Display(){
cout<cout<(2)<}
voidEmployee:
:
writeoffile(ofstream&fout){
fout<fout<}
#ifndefHEADER_KESHE3
#defineHEADER_KESHE3
#include"keshe2.h"
classSalariedEmployee:
virtualpublicEmployee{
intleaveday;
doublesalary;
public:
SalariedEmployee(unsigned,string,Birthdate,string,int,double);
SalariedEmployee(Employee&,int,double);
voidSetLeaveDay(int);
voidSetSalary(double);
intGetLeaveDay()const;
doubleGetSalary()const;
virtualdoublePay()const;
virtualvoidDisplay();
virtualvoidwriteoffile(ofstream&fout);
};
#endif
#include
#include
#include
#include
#include
usingnamespacestd;
#include"keshe3.h"
SalariedEmployee:
:
SalariedEmployee(unsignedi,stringn,Birthdateb,stringt,intl=0,doubles=3000):
Employee(i,n,b,t){
leaveday=l;
salary=s;
}
SalariedEmployee:
:
SalariedEmployee(Employee&e,intl,doubles):
Employee(e){
leaveday=l;
salary=s;
}
voidSalariedEmployee:
:
SetLeaveDay(intl){
leaveday=l;
}
voidSalariedEmployee:
:
SetSalary(doubles){
salary=s;
}
intSalariedEmployee:
:
GetLeaveDay()const{
returnleaveday;
}
doubleSalariedEmployee:
:
GetSalary()const{
returnsalary;
}
doubleSalariedEmployee:
:
Pay()const{
unsignedm;
SYSTEMTIMEsys;
GetLocalTime(&sys);
m=sys.wMonth;
if(GetReward(m))
return(salary+30*leaveday+200);
else
returnsalary+30*leaveday;
}
voidSalariedEmployee:
:
Display(){
unsignedm;
cout<<"******************************固定薪金职员***********************************"<cout<cout<<"固定月薪"<Employee:
:
Display();
SYSTEMTIMEsys;
GetLocalTime(&sys);
m=sys.wMonth;
if(GetReward(m))
cout<<"200";
else
cout<<"0";
cout<if(GetDraw())
cout<<"是"<else
cout<<"否"<}
voidSalariedEmployee:
:
writeoffile(ofstream&fout){
fout<<"G"<Employee:
:
writeoffile(fout);
fout<}
#ifndefHEADER_KESHE4
#defineHEADER_KESHE4
#include"keshe3.h"
classHourlyEmployee:
publicEmployee{
inthour;
doublesperhour;
public:
HourlyEmployee(unsigned,string,Birthdate,string,int,double);
HourlyEmployee(Employee&,int,double);
voidSetHour(int);
voidSetSperHour(double);
intGetHour()const;
doubleGetSperHour()const;
virtualdoublePay()const;
virtualvoidDisplay();
virtualvoidwriteoffile(ofstream&fout);
};
#endif
#include
#include
#include
#include
#include
usingnamespacestd;
#include"keshe4.h"
HourlyEmployee:
:
HourlyEmployee(unsignedi,stringn,Birthdateb,stringt,inth,doubles):
Employee(i,n,b,t){
hour=h;
sperhour=s;
}
HourlyEmployee:
:
HourlyEmployee(Employee&e,inth,doubles):
Employee(e){
hour=h;
sperhour=s;
}
voidHourlyEmployee:
:
SetHour(inth){
hour=h;
}
voidHourlyEmployee:
:
SetSperHour(doubles){
sperhour=s;
}
intHourlyEmployee:
:
GetHour()const{
returnhour;
}
doubleHourlyEmployee:
:
GetSperHour()const{
returnsperhour;
}
doubleHourlyEmployee:
:
Pay()const{
unsignedm;
SYSTEMTIMEsys;
GetLocalTime(&sys);
m=sys.wMonth;
if(GetReward(m))
return(sperhour*160+sperhour*1.5*(hour-160)+200);
else
return(sperhour*160+sperhour*1.5*(hour-160));
}
voidHourlyEmployee:
:
Display(){
unsignedm;
cout<<"***************************计时职员**********************************"<cout<cout<<"工作时长"<Employee:
:
Display();
SYSTEMTIMEsys;
GetLocalTime(&sys);
m=sys.wMonth;
if(GetReward(m))
cout<<"200";
else
cout<<"0";
cout<if(GetDraw())
cout<<"是"<else
cout<<"否"<}
voidHourlyEmployee:
:
writeoffile(ofstream&fout){
fout<<"J"<Employee:
:
writeoffile(fout);
fout<}
#ifndefHEADER_KESHE5
#defineHEADER_KESHE5
#include"keshe4.h"
classCommisionEmployee:
virtualpublicEmployee{
doublesale;
doubleratio;
public:
CommisionEmployee(unsigned,string,Birthdate,string,double,double);
CommisionEmployee(Employee&,double,double);
voidSetSale(double);
voidSetRatio(double);
doubleGetSale()const;
doubleGetRatio()const;
virtualdoublePay()const;
virtualvoidDisplay();
virtualvoidwriteoffile(ofstream&fout);
};
#endif
#include
#include
#include
#include
#include
usingnamespacestd;
#include"keshe5.h"
CommisionEmployee:
:
CommisionEmployee(unsignedi,stringn,Birthdateb,stringt,doubles,doublea):
Employee(i,n,b,t){
sale=s;
ratio=a;
}
CommisionEmployee:
:
CommisionEmployee(Employee&e,doubles,doublea):
Employee(e){
sale=s;
ratio=a;
}
voidCommisionEmployee:
:
SetSale(doubles){
sale=s;
}
voidCommisionEmployee:
:
SetRatio(doublea){
ratio=a;
}
doubleCommisionEmployee:
:
GetSale()const{
returnsale;
}
doubleCommisionEmployee:
:
GetRatio()const{
returnratio;
}
doubleCommisionEmployee:
:
Pay()const{
unsignedm;
SYSTEMTIMEsys;
GetLocalTime(&sys);
m=sys.wMonth;
if(sale<30000){
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
returnsale*ratio;
}
}
voidCommisionEmployee:
:
Display(){
unsignedm;
cout<<"**************************普通销售员**********************************"<cout<cout<<"销售额"<Employee:
:
Display();
SYSTEMTIMEsys;
GetLocalTime(&sys);
m=sys.wMonth;
if(GetReward(m))
cout<<"200";
else
cout<<"0";
cout<if(sale<30000)
cout<<(30000-sale)*(2.0/1000)<else
cout<<"0"<if(GetDraw())
cout<<"是"<else
cout<<"否"<<