1、C+仓库管理系统222020年5月29日文档仅供参考employee.hemployee(员工)的类声明头文件employee.cpp包含employee类的实现代码Salesman.hSalesman(售货员)的类声明头文件Salesman.cpp包含Salesman类的实现代码Warehouseman.hwarehouseman(库管员)的类声明头文件Warehouseman.cpp包含Warehouseman类的实现代码manager.hmanager (经理)的类声明头文件manager.cpp包含manager类的实现代码EmployeeList.hEmployeeList类(员工链
2、表)的类声明头文件EmployeeList.cpp包含EmployeeList类的实现代码main.cpp主程序/*/ employee.h */*#ifndef H_EMPLOYEE#define H_EMPLOYEEclass employee /基类(员工)private:int number;/员工编号charAddress100;/家庭地址protected:char name30;/员工姓名float fixedSalary;/固定工资float MonthSalary;/月薪public:employee();/构造函数,录入员工个人信息void ShowInfor();/显示员
3、工个人及工资信息void RecordInfor(char* pInfBuffer);/将个人信息写入缓冲区/获得工作类别virtualchar * GetWorkStyle() = 0 ;/计算员工工资的虚函数,因为只提供一个统一的接口,因此不需要添加任何实际的代码virtual void CountSalary()=0;#endif/*/ employee.cpp */*#include employee.h#include iostream.h#include stdio.h/构造函数,录入员工个人信息employee:employee()coutendl;/录入员工姓名coutname
4、;/录入员工编号coutnumber;/检查员工编号,保证编号正确while ( number9999 ) cout endl number;/录入家庭地址coutAddress;/默认初始月薪为零MonthSalary = 0.0;/显示员工个人及工资信息void employee:ShowInfor()coutendl;/显示员工姓名cout员工姓名: nameendl;/显示员工编号cout员工编号: numberendl;/显示家庭地址cout家庭地址: Addressendl;/显示工作类别cout工作类别: GetWorkStyle()endl;/显示月薪if (MonthSala
5、ry = 0.0) cout月薪: 尚未计算endl;elsecout月薪: MonthSalaryendl;/将个人信息写入缓冲区void employee:RecordInfor(char* pInfBuffer)intj;j = sprintf(pInfBuffer , 员工姓名:%srn,name);j += sprintf(pInfBuffer + j,员工编号:%drn,number);j += sprintf(pInfBuffer + j,家庭地址:%srn,Address);j += sprintf(pInfBuffer + j,工作类别:%srn,GetWorkStyle()
6、;if (MonthSalary = 0.0) j += sprintf(pInfBuffer + j,月薪: 尚未计算rnrn);elsej += sprintf(pInfBuffer + j,月薪: %frnrn,MonthSalary);/*/ Salesman.h */*#ifndef H_SALESMAN#define H_SALESMAN#include employee.h/售货员类class Salesman : publicemployeeprivate:float saleSum;/售货员的销售额float getRate; /售货员的提成比率public:Salesman
7、();/构造函数,录入售货员个人信息char* GetWorkStyle();/获得工作类别void CountSalary();/计算售货员的工资;#endif/*/ Salesman.cpp */*#include Salesman.h#include iostream.h/构造函数,录入售货员个人信息Salesman:Salesman()coutendl;/录入售货员的固定月薪coutfixedSalary;/录入售货员的当月销售额coutgetRate;/获得工作类别char * Salesman:GetWorkStyle()return 售货员;/计算售货员的工资void Sales
8、man:CountSalary()/得到售货员的当月销售额cout请输入售货员name的当月销售额saleSum;/工资固定工资营业额提成比率MonthSalary = fixedSalary + saleSum * getRate;/*/ warehouseman.h */*#ifndef H_WAREHOUSEMAN#define H_WAREHOUSEMAN#include employee.h/库管员类class Warehouseman : publicemployeeprivate:float bonus;/库管员的奖金public:Warehouseman();/构造函数,录入库
9、管员个人信息char * GetWorkStyle();/获得工作类别void CountSalary();/计算库管员的工资;#endif/*/ warehouseman.cpp */*#include Warehouseman.h#include iostream.h/构造函数,录入库管员个人信息Warehouseman:Warehouseman()coutendl;/录入库管员的固定月薪coutfixedSalary;/获得工作类别char * Warehouseman:GetWorkStyle()return 库管员;/计算库管员的工资void Warehouseman:CountSa
10、lary()/得到库管员的当月奖金cout请输入库管员name的当月奖金bonus;/工资固定工资当月奖金MonthSalary = fixedSalary + bonus;/*/ Manager.h */*#ifndef H_MANAGER#define H_MANAGER#include Employee.h/经理类class Manager : publicEmployeeprivate:float OfficeExpense;/经理的办公费用public:Manager();/构造函数,录入经理个人信息char * GetWorkStyle();/获得工作类别void CountSal
11、ary();/计算经理的工资;#endif/*/ Manager.cpp */*#include Manager.h#include iostream.h/构造函数,录入经理个人信息Manager:Manager()coutendl;/录入经理的固定月薪cout 请输入经理的固定月薪:fixedSalary;/获得工作类别char * Manager:GetWorkStyle()return 经理;/计算经理的工资void Manager:CountSalary()/得到经理的当月办公费用cout请输入经理name的当月办公费用OfficeExpense;/月薪固定工资当月办公费用MonthS
12、alary = fixedSalary + OfficeExpense;/*/ EmployeeList.h */*#ifndef H_EMPLOYEELIST#define H_EMPLOYEELIST#include employee.h#defineNULL0/定义一个包含员工类对象的节点结构struct employeeNodeemployee* pEmployee;employeeNode* pNext;class EmployeeListprivate:employeeNode* pEmpListRoot;/员工类对象的链表的根指针public:EmployeeList();/析构
13、函数EmployeeList();/将一个包含员工类对象的节点添加到链表中voidAddList(employee*pEmployee);/计算所有员工的月薪voidCaculateAllSalary();/显示所有员工的详细信息voidShowAllInfo();/将所有员工的详细信息保存到纪录文件上voidSaveAllRecord();#endif/*/ EmployeeList.cpp */*#include EmployeeList.h#include iostream.h#include fstream.h#include stdio.h#include string.hEmplo
14、yeeList:EmployeeList()pEmpListRoot = NULL;/将一个包含员工类对象的节点添加到链表中voidEmployeeList:AddList(employee*pEmployee)employeeNode* pEmpNode;pEmpNode = newemployeeNode();pEmpNode-pEmployee = pEmployee;pEmpNode-pNext = pEmpListRoot;pEmpListRoot = pEmpNode;/计算所有员工的月薪voidEmployeeList:CaculateAllSalary()employeeNod
15、e*pTempNode;/计算员工链表中所有员工的月薪pTempNode = pEmpListRoot;while (pTempNode) pTempNode-pEmployee-CountSalary();pTempNode = pTempNode-pNext;/显示所有员工的详细信息voidEmployeeList:ShowAllInfo()employeeNode* pTempNode;/显示员工链表中所有员工的信息cout所有员工的个人信息如下:pEmployee-ShowInfor();pTempNode = pTempNode-pNext;/将所有员工的详细信息保存到纪录文件上vo
16、idEmployeeList:SaveAllRecord()ofstreammyFile;charsAllBuffer1000000= 0;charsSingleBuffer1000=0;intj;myFile.open(info.txt,ios:app|ios:binary);if (!myFile) cerr打开记录文件时出现错误!pEmployee-RecordInfor(sSingleBuffer);/加入到总的字符串缓冲区中strcat(sAllBuffer,sSingleBuffer);pTempNode = pTempNode-pNext;myFile.write(sAllBuf
17、fer,strlen(sAllBuffer);myFile.close();EmployeeList:EmployeeList()employeeNode*pTempNode;pTempNode = pEmpListRoot;while (pTempNode) pEmpListRoot = pEmpListRoot-pNext;deletepTempNode-pEmployee;deletepTempNode;pTempNode = pEmpListRoot;/*/ main.cpp */ 主程序 */*#include stdlib.h#include stdio.h#include con
18、io.h#include employee.h#include Salesman.h#include Warehouseman.h#include Manager.h#include iostream.h#include EmployeeList.hvoid main()charopr;/操作项EmployeeListEL;employee* pEmployee;cout endl =商场员工信息登记系统=endl;while (true) /建立循环操作cout endl 请选择操作:endl;cout1.添加一个售货员endl;cout2.添加一个库管员endl;cout3.添加一个经理e
19、ndl;cout4.计算所有员工的月薪endl;cout5.显示所有员工的详细信息endl;cout6.保存并退出endl;/检查用户输入while ( opr!=1 & opr!=2 & opr!=3& opr!=4& opr!=5& opr!=6)cout您的输入有误,请重新输入! opr;/读入用户的操作项cin opr; switch(opr) /添加一个售货员case 1:pEmployee = newSalesman();EL.AddList(pEmployee);break;/添加一个库管员case 2:pEmployee = newWarehouseman();EL.AddList(pEmployee);break;/添加一个经理case 3:pEmployee = newManager();EL.AddList(pEmployee);break;case 4:/计算员工链表中所有员工的月薪EL.CaculateAllSalary();break;case 5:/显示员工链表中所有员工的详细信息EL.ShowAllInfo();break;case 6:/将所有员工的详细信息保存到纪录文件上,并退出EL.SaveAllRecord();return;break;default:break;