#include #include #include using namespace std; const N=50; // 定义系统可录入的员工最大数值 string Ename[N]; long Enum[N]; char Esex[N]; int Eage[N]; char Emarriage[N]; int Edepart[N]; int Eposition[N]; int Edegree[50]; int Eworktime[N]; float Epay[N]; class Employee { public: string Employeename; long Employeenum; char Employeesex; int Employeeage; char Employeemarriage; int Employeedepart; int Employeeposition; int Employeedegree; int Employeeworktime; float Employeepay; static long EmployeeMaxNum; static float EmployeeBasePay; void NewInfo(); void ShowInfo(); void showall(); void showdepart(int depart); void showdegree(int degree); void showage(int min,int max); void shownum(long number); void RefreshInfo(); void DeleteInfo(); float Pay(int Employeegrade); static int MaxNum(); }; class DBOperate { public: string Employeename; long Employeenum; char Employeesex; int Employeeage; char Employeemarriage; int Employeedepart; int Employeeposition; int Employeedegree; int Employeeworktime; float Employeepay; static long EmployeeMaxNum; static float EmployeeBasePay; void WriteIn(int iflag); void ReadOut(); void RefreshMaxNum(int iflag); //i=1 or -1 or 0 }; long Employee::EmployeeMaxNum = 1000; float Employee::EmployeeBasePay = 1500; int Employee::MaxNum() //返回系统已经存储的人数 { int MN = 0; ifstream myf; myf.open("EmployeeMaxNum.txt"); myf>>MN; cout<>Employee::Employeename; Employee::Employeenum = EmployeeMaxNum + Employee::MaxNum()+1; cout<<"新员工性别 (F为女性,M为男性): "; cin>>Employee::Employeesex; cout<<"新员工年龄: "; cin>>Employee::Employeeage; cout<<"新员工婚姻状况(Y为已婚,N为未婚): "; cin>>Employee::Employeemarriage; cout<<"新员工学历,请输入相应学历的序号: "<>Employee::Employeedegree; while(Employee::Employeedegree !=1&&Employee::Employeedegree !=2&&Employee::Employeedegree !=3&&Employee::Employeedegree !=4&&Employee::Employeedegree !=5) { cout<<"输入有误,请重新输入:"<>Employee::Employeedegree; } cout<<"新员工所在部门,请输入相应部门的序号:"<>Employee::Employeedepart; while(Employee::Employeedepart !=1&&Employee::Employeedepart !=2&&Employee::Employeedepart !=3&&Employee::Employeedepart !=4&&Employee::Employeedepart!=5) { cout<<"输入有误,请重新输入:"<>Employee::Employeedepart; } cout<<"新员工职位, 请输入相应职位的序号: "<>Employee::Employeeposition; while(Employee::Employeeposition !=1&&Employee::Employeeposition !=2&&Employee::Employeeposition !=3&&Employee::Employeeposition !=4&&Employee::Employeeposition !=5) { cout<<"输入有误,请重新输入:"<>Employee::Employeeposition; } cout<<"新员工的工作时(不需要输入单位): "; cin>>Employee::Employeeworktime; Employee::Employeepay = Employee::Pay(Employee::Employeeposition); DBOperate dbo; dbo.ReadOut(); int MaxNum = Employee::MaxNum(); Enum[MaxNum] = Employee::Employeenum; Ename[MaxNum] = Employee::Employeename; Esex[MaxNum] = Employee::Employeesex; Eage[MaxNum] = Employee::Employeeage; Emarriage[MaxNum] = Employee::Employeemarriage; Edegree[MaxNum] = Employee::Employeedegree; Edepart[MaxNum] = Employee::Employeedepart; Eposition[MaxNum] = Employee::Employeeposition; Eworktime[MaxNum] = Employee::Employeeworktime; Epay[MaxNum] = Employee::Employeepay; dbo.WriteIn(1); cout<<" 添加新成员成功!"<>choice1; switch(choice1) { case 1: showall();break; case 2: cout<<"请输入要查询职工的部门编号: [1:董事会 2:市场部 3:公关部 4:客服中心 5:信息中心] " ; cin>>choice2; e.showdepart(choice2);break; case 3: cout<<"请输入要查询职工的学历编号: [1:初中 2:高中 3:本科 4:硕士 5:博士] "; cin>>choice2; e.showdegree(choice2);break; case 4: cout<<"请输入要查询的年龄范围: "; cout<<"最小值: "; cin>>min; cout<<"最大值: "; cin>>max; e.showage(min,max);break; case 5: cout<<"请输入要查询的员工号: "; cin>>searchnum; e.shownum(searchnum);break; default: cout<<"出错啦! "<"<"<"<"<"<"<=min&&Eage[i]<=max) { long number = Enum[i]; shownum(number); } else continue; } } void Employee::shownum(long number) //按员工编号输出函数 { int i; for(i=0;i"<"<"; if(Esex[i]=='F') cout<<"女 "<"<"; if(Emarriage[i]=='Y') cout<<"已婚 "<"; switch (Edegree[i]) { case 1:cout<<"初 中 "<"; switch (Edepart[i]) { case 1:cout<<"董事会 "<"; switch (Eposition[i]) { case 1:cout<<"临时成员 "<"<"<"; cin>>cNum; int MN; MN = Employee::MaxNum(); for(int i=0;i>Employee::Employeename; Ename[i] = Employee::Employeename; cout<<"新员工性别: [F为女性,M为男性]: "; cin>>Employee::Employeesex; Esex[i] = Employee::Employeesex; cout<<"新员工年龄: "; cin>>Employee::Employeeage; Eage[i] = Employee::Employeeage; cout<<"新员工婚姻状况(Y为已婚,N为未婚): "; cin>>Employee::Employeemarriage; Emarriage[i] = Employee::Employeemarriage; cout<<"新员工学历,请输入相应学历的序号:"<>Employee::Employeedegree; while(Employee::Employeedegree !=1&&Employee::Employeedegree !=2&&Employee::Employeedegree !=3&&Employee::Employeedegree !=4&&Employee::Employeedegree !=5) { cout<<"输入有误,请重新输入:"<>Employee::Employeedegree; } Edegree[i] = Employee::Employeedegree; cout<<"新员工所在部门,请输入相应部门的序号: "<>Employee::Employeedepart; while(Employee::Employeedepart !=1&&Employee::Employeedepart !=2&&Employee::Employeedepart !=3&&Employee::Employeedepart !=4&&Employee::Employeedepart!=5) { cout<<"输入有误,请重新输入:"<>Employee::Employeedepart; } Edepart[i] = Employee::Employeedepart; cout<<"新员工职位,请输入相应职位的序号:"<>Employee::Employeeposition; while(Employee::Employeeposition !=1&&Employee::Employeeposition !=2&&Employee::Employeeposition !=3&&Employee::Employeeposition !=4&&Employee::Employeeposition !=5) { cout<<"输入有误,请重新输入:"<>Employee::Employeeposition; } Eposition[i] = Employee::Employeeposition; cout<<"新员工的工作时 (不需要输入单位): "; cin>>Employee::Employeeworktime; Eworktime[i] = Employee::Employeeworktime; Epay[i] = Employee::Pay(Employee::Employeeposition); break; } } dbo.WriteIn(0); } void Employee::DeleteInfo() //删除员工数据的函数 { char tmp; int cNum = 1000; DBOperate dbo; dbo.ReadOut(); void Employee::shownum(long number); cout<<"请输入您要修改的员工编号>: "; cin>>cNum; int MN; MN = Employee::MaxNum(); for(int i=0;i>tmp; if(tmp=='Y') { if(i==MN-1) dbo.WriteIn(-1); else { for(int j=i;j>DBOperate::Employeenum>>DBOperate::Employeename>>DBOperate::Employeesex>>DBOperate::Employeeage>>DBOperate::Employeemarriage >>DBOperate::Employeedegree>>DBOperate::Employeedepart>>DBOperate::Employeeposition>>DBOperate::Employeeworktime>>DBOperate::Employeepay; Enum[i] = DBOperate::Employeenum; Ename[i] = DBOperate::Employeename; Esex[i] = DBOperate::Employeesex; Eage[i] = DBOperate::Employeeage; Emarriage[i] = DBOperate::Employeemarriage; Edegree[i] = DBOperate::Employeedegree; Edepart[i] = DBOperate::Employeedepart; Eposition[i] = DBOperate::Employeeposition; Eworktime[i] = DBOperate::Employeeworktime; Epay[i] = DBOperate::Employeepay; } myf.close(); } void DBOperate::RefreshMaxNum(int iflag) //更新系统中员工计数文件的函数 { int MaxNum = 0; ifstream myif("EmployeeMaxNum.txt"); myif>>MaxNum; myif.close(); MaxNum = MaxNum+iflag; ofstream myof("EmployeeMaxNum.txt"); myof<>select; Employee e; DBOperate dbo; switch(select) { case 1: e.NewInfo(); break; case 2: dbo.ReadOut(); e.ShowInfo(); break; case 3: e.RefreshInfo(); break; case 4: e.DeleteInfo(); break; case 5: break; default: cout<<"命令错误!"<