#ifndef HEADER_KESHE1
#define HEADER_KESHE1
class 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){
return out< } friend istream& operator>>(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 < fout < return fout; } friend ifstream& operator>>(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 #include using namespace std; #include"keshe1.h" Birthdate::Birthdate(unsigned y,unsigned m){ year=y; month=m; } void Birthdate::SetYear(unsigned 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 #include"keshe1.h" class Employee{ unsigned ID; string name; Birthdate bir; string type; bool reward; bool 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; 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 #include using namespace std; #include"keshe2.h" Employee::Employee(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=https://www.doczj.com/doc/fc6160751.html,; 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); 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; } 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(){ cout< cout< void Employee::writeoffile(ofstream& fout){ fout< fout< } #ifndef HEADER_KESHE3 #define HEADER_KESHE3 #include"keshe2.h" class SalariedEmployee:virtual public 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() ; virtual void writeoffile(ofstream& fout) ; }; #endif #include #include #include #include #include using namespace std; #include"keshe3.h" SalariedEmployee::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::SalariedEmployee(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 SalariedEmployee::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<<"******************************固定薪金职员***********************************"< cout< cout<<"固定月薪"< Employee::Display(); SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m)) cout<<"200"; else cout<<"0"; cout< if(GetDraw()) cout<<"是"< else cout<<"否"< } void SalariedEmployee::writeoffile(ofstream& fout){ fout<<"G "< Employee::writeoffile(fout); fout< } #ifndef HEADER_KESHE4 #define HEADER_KESHE4 #include"keshe3.h" class HourlyEmployee:public Employee{ int hour; double sperhour; public: HourlyEmployee(unsigned ,string,Birthdate,string,int,double); HourlyEmployee(Employee&,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 #include using namespace std; #include"keshe4.h" HourlyEmployee::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){ sperhour=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+sperhour*1.5*(hour-160)); } void HourlyEmployee::Display(){ unsigned m; cout<<"***************************计时职员**********************************"< cout< cout<<"工作时长"< Employee::Display(); SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m)) cout<<"200"; else cout<<"0"; cout< if(GetDraw()) cout<<"是"< else cout<<"否"< } void HourlyEmployee::writeoffile(ofstream& fout){ fout<<"J "< Employee::writeoffile(fout); fout< } #ifndef HEADER_KESHE5 #define HEADER_KESHE5 #include"keshe4.h" class 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 double Pay() const; virtual void Display() ; virtual void writeoffile(ofstream& fout) ; }; #endif #include #include #include #include #include using namespace std; #include"keshe5.h" CommisionEmployee::CommisionEmployee(unsigned i,string n,Birthdate b,string t,double s,double a): Employee(i,n,b,t){ sale=s; ratio=a; } CommisionEmployee::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; } double CommisionEmployee::Pay()const{ unsigned m; SYSTEMTIME sys; 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 return sale*ratio; } void CommisionEmployee::Display(){ unsigned m; cout<<"**************************普通销售员**********************************"< cout< cout<<"销售额"< Employee::Display(); SYSTEMTIME sys; 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<<"否"< } void CommisionEmployee::writeoffile(ofstream& fout){ fout<<"P "< Employee::writeoffile(fout); fout< } #ifndef HEADER_KESHE6 #define HEADER_KESHE6 #include"keshe5.h" class BasePlus:public SalariedEmployee,public CommisionEmployee{ public: BasePlus(unsigned i,string,Birthdate,string,double,int,double,double); BasePlus(CommisionEmployee&, SalariedEmployee&); virtual double Pay() const; virtual void Display() ; virtual void writeoffile(ofstream& fout) ; }; #endif #include #include #include #include #include using namespace std; #include"keshe6.h" BasePlus::BasePlus(unsigned i,string n,Birthdate b,string t,double s,int l,double a,double o): Employee(i,n,b,t),SalariedEmployee(i,n,b,t,l,s),CommisionEmployee(i,n,b,t,a,o){} BasePlus::BasePlus(CommisionEmployee& c,SalariedEmployee& s):Employee(c),CommisionEmployee(c),SalariedEmployee(s){} double BasePlus::Pay() const{ unsigned m; SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetSale()<30000){ if(GetReward(m)) return (GetSalary()+GetSale()*GetRatio()-GetLeaveDay()*30-(30000-GetSale())*(2.0/1000)+200); else return (GetSalary()+GetSale()*GetRatio()-GetLeaveDay()*30-(30000-GetSale())*(2.0/1000)); } else{ if(GetReward(m)) return (GetSalary()+GetSale()*GetRatio()-GetLeaveDay()*30+200); else return (GetSalary()+GetSale()*GetRatio()-GetLeaveDay()*30); } } void BasePlus::Display(){ unsigned m; cout<<"***************************带薪销售员**************************"< cout< cout<<"销售额"< Employee::Display(); SYSTEMTIME sys; GetLocalTime(&sys); m=sys.wMonth; if(GetReward(m)) cout<<"200"; else cout<<"0"; cout< if(GetSale()<30000) cout<<(GetLeaveDay()*30+(30000-GetSale())*(2.0/1000))< else cout< if(GetDraw()) cout<<"是"< else cout<<"否"< } void BasePlus::writeoffile(ofstream& fout){ fout<<"D "< Employee::writeoffile(fout); fout< } class Node { Employee& employee; Node *next,*prev; public: Node(Employee&); Employee* GetEmployee(); Node* GetNext() const; void SetNext(Node*); Node* GetPrev() const; void SetPrev(Node*); }; #endif #include #include #include #include using namespace std; #include"keshe7.h" Node::Node(Employee& e):employee(e){ next=NULL; prev=NULL; } Employee* Node::GetEmployee(){ return &employee; } Node* Node::GetNext() const{ return next; } void Node::SetNext(Node* n){ next=n; } Node* Node::GetPrev()const{ return prev; } void Node::SetPrev(Node* n){ prev=n; } #ifndef HEADER_KESHE8 #define HEADER_KESHE8 #include"keshe7.h" class EmployeeList { int size; Node* pHead; public: EmployeeList(); ~EmployeeList(); void Display() ; bool Append(Employee&); bool Del(unsigned); Employee* Find(unsigned) const; Employee* Find(EmployeeList&,string) const; int GetSize() const; bool IsEmpty() const; void Clear(); Node* First() const; Node* End(); friend ofstream& operator<<(ofstream& out,EmployeeList l){ Node* p=l.pHead; while(p){ p->GetEmployee()->writeoffile(out); p=p->GetNext(); } return out; } }; #endif #include #include #include #include using namespace std; #include"keshe8.h" EmployeeList::EmployeeList(){ size=0; pHead=NULL; } EmployeeList::~EmployeeList(){ delete pHead; } void EmployeeList::Display(){ if(!pHead) cout<<"没有员工"< else{ Node *p=pHead; while(p){ (p->GetEmployee())->Display(); p=p->GetNext(); } } } bool EmployeeList::Append(Employee& e){ size++; Node *pNew=new Node(e); if(!pNew) return false; if(!pHead) pHead=pNew; else{ Node* p=End(); p->SetNext(pNew); pNew->SetPrev(p); } return true; } bool EmployeeList::Del(unsigned s){ Node* p=pHead; Node* p1; Node* p2; if(!pHead) return false; while(p->GetEmployee()->GetId()!=s){ p=p->GetNext(); } if(size==1){ size--; delete pHead; cout<<"该公司没有员工"< } else if(s==pHead->GetEmployee()->GetId()){ pHead=pHead->GetNext(); delete p; } else if(s==End()->GetEmployee()->GetId()){ size--; p1=p->GetPrev(); p1->SetNext(NULL); delete p; } else{ size--; p1=p->GetPrev(); p2=p->GetNext(); p1->SetNext(p2); p2->SetPrev(p1); delete p; } return true; } Employee* EmployeeList::Find(unsigned n)const{ Node* p=First(); while(p){ if((p->GetEmployee())->GetId()==n) break; p=p->GetNext(); } if(p==NULL){ cout<<"不存在编号为"< return 0; } else return p->GetEmployee(); } Employee* EmployeeList::Find(EmployeeList& e,string n)const{ Node* p=e.pHead; for(int i=1;i<=e.size;i++) if((p->GetEmployee())->GetName()==n) if(i>e.size){ cout<<"无该职员"< return 0; } else return p->GetEmployee(); } int EmployeeList::GetSize()const{ return size; } bool EmployeeList::IsEmpty() const{ if(size<=0) return true; else return false; } void EmployeeList::Clear(){ size=0; Node* p=pHead; while(p){ pHead=p; p=pHead->GetNext(); delete pHead; } } Node* EmployeeList::First()const{ return pHead; } Node* EmployeeList::End(){ Node* p=pHead; while(p->GetNext()) p=p->GetNext(); return p; } #include #include #include #include using namespace std; #include"keshe8.h" static unsigned code=0; Birthdate& add(); void first(EmployeeList& j); void initialize(EmployeeList& j); string putinformation(EmployeeList& j){ char c; int l,h; bool draw; string s1,n,s; unsigned y,d,m; double sa,sp,sal,r; cout<<"请输入文件的路径!"< cin>>s; ifstream fin(s.c_str()); try{if(!fin) throw s; } catch(string s){ cout< } while(fin>>c){ fin>>d>>n>>y>>m>>s1>>draw; if(d>code) Birthdate b(y,m); switch(c){ case'G':{ fin>>sa>>l; SalariedEmployee *e=new SalariedEmployee(d,n,b,s1,l,sa); e->SetDraw(draw); j.Append(*e); } break; case'J':{ fin>>h>>sp; HourlyEmployee *e=new HourlyEmployee(d,n,b,s1,h,sp); e->SetDraw(draw); j.Append(*e); } break; case'P':{ fin>>sal>>r; CommisionEmployee *e=new CommisionEmployee(d,n,b,s1,sal,r); e->SetDraw(draw); j.Append(*e); } break; case'D':{ fin>>sa>>sal>>r>>l; BasePlus *e=new BasePlus(d,n,b,s1,sa,l,sal,r); e->SetDraw(draw); j.Append(*e); } break; } } return s; } void first(EmployeeList& j){ if(j.GetSize()) j.Display(); else { cout<<"**错误操作!!!**"< cout<<"初始化系统信息"< initialize(j); system("cls"); } } void initialize(EmployeeList& j){ string s,name; double salary; int a=1,choice,leaveday; while(a){ cout<<"**********菜单***********"< cout<<"1.添加固定薪水员工数据"< cout<<"2.添加计时员工数据"< cout<<"3.添加普通销售员工数据"< cout<<"4.带薪销售员工数据"< cout<<"5.员工已完全记录,退出"< cout<<"请输入你的选择:"< cin>>choice; switch(choice){ case 1:{ ++code; cout<<"请输入员工的名字"< cin>>name; cout<<"请输入员工的工资"< cin>>salary; cout<<"请输入员工请假的天数"< cin>>leaveday; SalariedEmployee *e=new SalariedEmployee(code,name,add(),"固薪",leaveday,salary); j.Append(*e); } break; case 2:{ int time; double timesalary; cout<<"请输入员工的名字"< cin>>name; cout<<"请输入其工作时长"< cin>>time; cout<<"请输入其时薪"< cin>>timesalary; ++code; HourlyEmployee *e=new HourlyEmployee(code,name,add(),"计时",time,timesalary); j.Append(*e); } break; case 3:{ double sale,ratio; cout<<"请输入员工的名字"< cin>>name; cout<<"请输入其销售额"< cin>>sale; cout<<"请输入其提成比例"< cin>>ratio; ++code; CommisionEmployee *e=new CommisionEmployee(code,name,add(),"普销",sale,ratio); j.Append(*e); } break; case 4:{ unsigned leaveday; double sale,salary,ratio; cout<<"请输入员工的名字"< cin>>name; cout<<"请输入其固定工资"< cin>>salary; cout<<"请输入其请假的天数"< cin>>leaveday; cout<<"请输入其销售额"< cin>>sale; cout<<"请输入其提成比例"< cin>>ratio; ++code; BasePlus *e=new BasePlus(code,name,add(),"带销",salary,leaveday,sale,ratio); j.Append(*e); } break; case 5: a=0; break; default:cout<<"没有该部门,请重新输入!"< } system("cls"); } } bool Id(EmployeeList& j,unsigned id){ int i,a=1; Employee* p=j.Find(id); if(!p) return false; j.Find(id)->Display(); cout<<"1.修改该员工的是否领取工资的情况"< cout<<"2.修改该员工的生日"< cout<<"3.修改该员工的工种"< cout<<"4.修改该员工的基本薪水"< cout<<"5.修改该职员的工作时长"< cout<<"6.修改该职员的时薪"< cout<<"7.修改该员工的销售额"< cout<<"8.修改该员工的提取比例"< cout<<"9.修改该员工的请假天数"< cout<<"10.修改完成,退出"< while(a){ cout<<"请输入你的选择"< cin>>i; switch(i){ case 1:{ bool f;int m; cout<<"1.已领取工资"< cout<<"2.没有领取"< cout<<"请输入你的选择"< cin>>f; cout<<"1.确认修改"< cout<<"2.退出"< cin>>m; if(m==1){ j.Find(id)->SetDraw(f); j.Find(id)->Display(); } else break; } break; case 2:{ int m; unsigned ye,mo; cout<<"请输入该职员的出生年份以及月份"< cin>>ye>>mo; cout<<"1.确认修改"< cout<<"2.退出"< cin>>m; if(m==1){ j.Find(id)->SetBirth(ye,mo); j.Find(id)->Display(); } else break; } break; case 3:{ int ho,le; string ty; double sh,sa,sal,ra; cout<<"请输入该职员的工作类型"< cin>>ty; j.Del(id); if(ty=="带销"){ cout<<"请输入该职员的固定工资"< cin>>sa; cout<<"请输入该职员的请假天数"< cin>>le; cout<<"请输入该职员的销售额"< cin>>sal; cout<<"请输入该职员的提成比例"< cin>>ra; cout< BasePlus* b=new BasePlus(id,p->GetName(),p->GetBirthday(),"带销",sa,le,sal,ra); j.Append(*b); j.Find(id)->Display(); } else if(ty=="固薪"){ cout<<"请输入该职员的固定工资"< cin>>sa; cout<<"请输入该职员的请假天数"< cin>>le; SalariedEmployee* s=new SalariedEmployee(id,p->GetName(),p->GetBirthday(),"固薪",sa,le); j.Append(*s); j.Find(id)->Display(); } else if(ty=="计时"){ cout<<"请输入该职员的工作时长"< cin>>ho; cout<<"请输入该职员的时薪"< cin>>sh; HourlyEmployee* h=new HourlyEmployee(id,p->GetName(),p->GetBirthday(),"计时",ho,sh); j.Append(*h); j.Find(id)->Display(); } else if(ty=="普销"){ CommisionEmployee* c=new CommisionEmployee(id,p->GetName(),p->GetBirthday(),"普销",sal,ra); j.Append(*c); j.Find(id)->Display(); } else{ cout<<"不存在该类型"< j.Append(*p); } } break; case 4:{ double sa; cout<<"请输入该职员的固定工资"< cin>>sa; SalariedEmployee* em=dynamic_cast em->SetSalary(sa); j.Find(id)->Display(); } break; case 5:{ int ho; cout<<"请输入该职员的工作时长"< cin>>ho; dynamic_cast j.Find(id)->Display(); } break; case 6:{ double sh; cout<<"请输入该职员的时薪"< cin>>sh; dynamic_cast j.Find(id)->Display(); } break; case 7:{ double sal; cout<<"请输入该职员的销售额"< cin>>sal; dynamic_cast j.Find(id)->Display(); } break; case 8:{ double ra; cout<<"请输入该职员的提成比例"< cin>>ra; dynamic_cast j.Find(id)->Display(); } break; case 9:{ int le; cout<<"请输入该职员的请假天数"< cin>>le; dynamic_cast } break; case 10:a=0;break; default:cout<<"错误输入"< } } return true; } Birthdate& add(){ unsigned y,m; cout<<"请输入员工的出生年份"< cin>>y; cout<<"请输入员工的出生月份"< cin>>m; Birthdate *e=new Birthdate(y,m); return *e; } #include #include #include #include using namespace std; #include"keshe8.h" void first(EmployeeList& j); void initialize(EmployeeList& j); bool Id(EmployeeList& j,unsigned id); string putinformation(EmployeeList& j); void main(){ EmployeeList jiajia; int choice; unsigned id; string s=putinformation(jiajia); while(1){ cout<<"*********************欢迎访问佳佳公司网***********************"< cout<<"*********菜单*********"< cout<<"1.输出职工信息"< cout<<"2.添加新职工"< cout<<"3.删除职工信息"< cout<<"4.修改职工信息"< cout<<"5.输出指定职工信息"< cout<<"6.工资发放"< cout<<"7.保存退出"< cout<<"!特别提醒:保存"< cout<<"请输入你的选择"< cin>>choice; switch(choice){ case 1:first(jiajia); case 2: initialize(jiajia); jiajia.Display(); system("cls"); break; case 3:{ cout<<"请输入要删除的员工编号:"< cin>>id; if(!jiajia.Find(id)) break; else{ jiajia.Find(id)->Display(); cout<<"**确认输入**"< cout<<"1.删除"< cout<<"2.退出"< cout<<"请输入你的选择"<