您好,欢迎访问三七文档
#includeiostream.h#includefstream.h#includectype.h#includestring.h//全局数据,对象doubleManagerSalary=6000;//经理固定月薪doubleSalesManagerSalary=4000;//销售经理固定月薪doubleSalesManagerPercent=5;//销售经理提成%doubleSalesPercent=0.5;//销售人员提成%doubleWagePerHour=50;//技术人员小时工资intID;//员工标识classPerson//员工类{protected:intNo;//编号charName[20];//姓名intDuty;//岗位doubleEarning;//收入Person*next;//指向员工类的指针public:Person(charID,char*Name,intDuty){this-Duty=Duty;strcpy(this-Name,Name);this-No=ID;}virtualvoidCalcSalary()=0;//计算员工工资的方法virtualvoidOutput()=0;//输出员工信息函数friendclassCompany;//定义公司类为友元类};classManager:publicPerson//经理类{public:Manager(charID,char*Name,intDuty):Person(ID,Name,Duty){}voidCalcSalary(){Earning=ManagerSalary;}voidOutput(){CalcSalary();coutNo\tName\t经理\tEarningendl;}};classSalesManager:publicPerson//销售经理类{private:doubleAmounts;public:SalesManager(charID,char*Name,intDuty,doubleAmounts):Person(ID,Name,Duty){this-Amounts=Amounts;}doubleGetAmounts(){returnAmounts;}voidSetAmounts(doubles){Amounts=s;}voidCalcSalary(){Earning=SalesManagerSalary+Amounts*SalesManagerPercent/100;}voidOutput(){CalcSalary();coutNo\tName\t销售经理\tEarningendl;}};classTechnician:publicPerson//技术员类{private:doublet;public:Technician(charID,char*Name,intDuty,doubleT):Person(ID,Name,Duty){this-t=T;}doubleGetT(){returnt;}voidSetT(doubleT){this-t=T;}voidCalcSalary(){Earning=WagePerHour*t;}voidOutput(){CalcSalary();coutNo\tName\t技术员\tt\tEarningendl;}};classSales:publicPerson//销售员类{private:doubleAmount;public:Sales(charID,char*Name,intDuty,doubleAmount):Person(ID,Name,Duty){this-Amount=Amount;}doubleGetAmount(){returnAmount;}voidSetAmount(doubleAmount){this-Amount=Amount;}voidCalcSalary(){Earning=SalesPercent/100*Amount;}voidOutput(){CalcSalary();coutNo\tName\t销售员\tAmount\tEarningendl;}};classCompany//公司类{private:Person*Worker;//员工表voidClear();//清除内存中数据public:Company(){Worker=0;Load();}~Company(){Person*p;p=Worker;while(p){p=p-next;deleteWorker;Worker=p;}Worker=0;}voidAdd();//增加人员voidDelete();//删除人员voidModify();//修改人员voidQuery();//查询人员voidSet();//基础数据设置voidSave();//数据存盘(包括基础数据,人员数据)voidLoad();//数据装入(包括基础数据,人员数据)};voidCompany::Clear()//清除内存中人员数据{Person*p=Worker;while(p){Worker=p-next;deletep;p=Worker;}}voidCompany::Add(){Person*p;//新结点指针intDuty;charName[20];doubleAmount,Amounts,T;cout\n**新增员工**\n;//输入员工信息ID++;cout输入岗位(1-经理2-销售经理3-销售员4-技术员):;cinDuty;cout输入姓名:;cinName;if(Duty==2){cout本月销售额:;cinAmounts;}if(Duty==3){cout本月销售额:;cinAmount;}elseif(Duty==4){cout本月工作小时数:;cinT;}//创建新员工结点switch(Duty){case1:p=newManager(ID,Name,Duty);break;case2:p=newSalesManager(ID,Name,Duty,Amounts);break;case3:p=newSales(ID,Name,Duty,Amount);break;case4:p=newTechnician(ID,Name,Duty,T);break;}p-next=0;//员工结点加入链表if(Worker)//若已经存在结点{Person*p2;p2=Worker;while(p2-next)//查找尾结点{p2=p2-next;}p2-next=p;//连接}else//若不存在结点(表空){Worker=p;//连接}cout\t\t\t***添加成功***\n;}voidCompany::Delete()//删除人员{intNo;cout\n**删除员工**\n;coutID:;cinNo;//查找要删除的结点Person*p1,*p2;p1=Worker;while(p1){if(p1-No==No)break;else{p2=p1;p1=p1-next;}}//删除结点if(p1!=NULL)//若找到结点,则删除{if(p1==Worker)//若要删除的结点是第一个结点{Worker=p1-next;deletep1;}else//若要删除的结点是后续结点{p2-next=p1-next;deletep1;}cout找到并删除\n;}else//未找到结点cout人员未找到!\n;}voidCompany::Modify(){intNo,Duty;charName[20];doubleAmounts,Amount,T;cout\n**修改员工**\n;coutID:;cinNo;//查找要修改的结点Person*p1,*p2;p1=Worker;while(p1){if(p1-No==No)break;else{p2=p1;p1=p1-next;}}//修改结点if(p1!=NULL)//若找到结点{p1-Output();cout调整岗位(1-经理2-销售经理3-销售员4-技术员):;cinDuty;if(p1-Duty!=Duty)//若岗位发生变动{//修改其它数据cout输入姓名:;cinName;if(Duty==2){cout本月销售额:;cinAmounts;}if(Duty==3){cout本月销售额:;cinAmount;}elseif(Duty==4){cout本月工作小时数:;cinT;}//创建新员工结点Person*p3;switch(Duty){case1:p3=newManager(p1-No,Name,Duty);break;case2:p3=newSalesManager(p1-No,Name,Duty,Amounts);break;case3:p3=newSales(p1-No,Name,Duty,Amount);break;case4:p3=newTechnician(p1-No,Name,Duty,T);break;}//员工结点替换到链表p3-next=p1-next;if(p1==Worker)//若要替换的结点是第一个结点Worker=p3;else//若要删除的结点是后续结点p2-next=p3;//删除原来的员工结点deletep1;}else//若岗位没有变动{cout输入姓名:;cinp1-Name;if(Duty==2){cout本月销售额:;cinAmounts;((SalesManager*)p1)-SetAmounts(Amounts);}if(Duty==3){cout本月销售额:;cinAmount;((Sales*)p1)-SetAmount(Amount);}elseif(Duty==4){cout本月工作小时数:;cinT;((Technician*)p1)-SetT(T);}}cout\t***修改成功***\n;}else//未找到结点cout未找到要查询的人员!\n;}voidCompany::Query(){inti;Person*p1,*p2;p1=Worker;if(p1){cout请输入要查找的人的编号:;cini;while(p1){if(p1-No==i){break;}else{p2=p1;p1=p1-next;}}if(p1!=NULL){p1-Output();}else{charch;cout查无此人,按任意键返回菜单:;cinch;if(ch!='\0'){return;}}}}voidCompany::Set(){cout\n设置基础数据\n;cout经理固定月薪[ManagerSalary元]:;cinManagerSalary;cout销售经理固定月薪[SalesManagerSalary元]:;cinSalesManagerSalary;cout销售经理提成[SalesManagerPercent%]:;cinSalesManagerPercent;cout销售人员提成[SalesPercent%]:;cinSalesPercent;cout技术人员小时工资[WagePerHour(元/小时)]:;cinWagePerHour;cout员工标识[=ID]:;cinID;}voidCompany::Save()//数据存盘(包括基础数据,人员数据),均采用文本文件{ofstream
本文标题:公司管理系统源程序
链接地址:https://www.777doc.com/doc-567752 .html