2022年职工管理系统C++编程 .pdf
/*自己动手写的职工管理系统简单的文本操作写了一个基础类然后两个继承类经理和员工 需要再扩展的可以自己加和样例差不多没有特别难的地方都是简单操作文本操作在工程下建立in.txt 就行了代码容易看懂*/ #include #include #include using namespace std; #define N 10 int j1=0; int j2=0; class employee /基础类定义 protected: int num; char name20; char sex6; int age; int workday; char position20; char department20; public: /公有函数定义employee(char *Name= ,char *Sex= ,int a=0,int w=0,char *Position= ,char *Department= ); employee() int get_num(); /返回各个属性值char *getname(); char *getsex(); int G_age(); int G_workday(); char *Getposition(); char *Getdepartment(); void Input(); /输入数据函数void Output(); /输出函数; employee:employee(char *Name,char *Sex,int a,int w,char *Position,char *Department) /初始化函数 strcpy(name ,Name); strcpy(sex,Sex); age=a; workday=w; strcpy(position,Position); strcpy(department,Department); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 9 页 - - - - - - - - - int employee:get_num () /返回函数实现 return num; char *employee:getname() return name; char *employee:getsex() return sex; int employee:G_age() return age; int employee:G_workday() return workday; char *employee:Getposition () return position; char *employee:Getdepartment() return department; void employee:Input () /输入 coutname; coutsex; coutage; coutworkday; coutposition; coutdepartment; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 9 页 - - - - - - - - - void employee:Output() /输出 couttt 姓名 :nameendl; couttt 性别 :sexendl; couttt 年龄 :sexendl; couttt 参加工作年份:sexendl; couttt 职务 :sexendl; couttt 部门 :sexendl; class jingli:public virtual employee /继承类经理 public: jingli(char *Name= ,char *Sex= ,int a=0,int w=0,char *Position= ,char *Department= ); jingli() void Input(); void Output(); ; jingli:jingli(char *Name,char *Sex,int a,int w,char *Position,char *Department):employee( Name, Sex, a, w, Position, Department) /经理默认关键字为1 num=1; void jingli:Input () /继承类调用初始类函数 employee:Input(); void jingli:Output() employee:Output(); class worker:public virtual employee /继承类员工 public: worker(char *Name= ,char *Sex= ,int a=0,int w=0,char *Position= ,char *Department= ); worker() void Input(); void Output(); ; worker:worker(char *Name,char *Sex,int a,int w,char *Position,char *Department):employee( Name, Sex, a, w, Position, Department) /员工默认关键字为2 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 9 页 - - - - - - - - - num=2; void worker:Input() /继承类调用初始类函数 employee:Input(); void worker:Output() employee:Output(); class System /系统类主要实现步骤 employee A; jingli B10; worker C10; void infor1(int flag); /输入数据函数void save(); /初始化函数void search1(int h,char ch20); /查找函数void Interface1(); /目录函数public: System(); System() void In_information(); /调用相应功能的主函数void search(); void Interface(); ; System:System() /初始化 save(); void System:In_information() /增加数据的具体实现函数 int rev1; int again=1; char t; while(again) coutttt 1. 增加一位经理记录endl; coutttt 2. 增加一位工人记录endl; coutttt 3. 回退endl; coutrev1; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 9 页 - - - - - - - - - switch(rev1) case 1:infor1(rev1); /相应增加数据函数实现关键字rev1 判断员工或经理break; case 2:infor1(rev1); break; case 3:Interface(); break; default: coutttt 没有此员工 !endl; continue; coutttt 信息存储成功 !endl; coutt; coutendl; if(!(t=Y|t=y) again=0; Interface(); /返回目录 void System:infor1(int flag) /输入数据导入文本函数 if(flag=1) jingli A; A.Input(); Bj1=A; else worker D; D.Input(); Cj2=D; fstream outfile; outfile.open(in.txt,ios:out|ios:app|ios:ate); /打开文本添加数据至尾部if(!outfile) /调试期间怕出错添加的判断函数 cerrFile open or create error!endl; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 9 页 - - - - - - - - - exit(1); if(flag=1) /导入到文本中更新数据 outfileflag Bj1.getname() Bj1.getsex() Bj1.G_age() Bj1.G_workday() Bj1.Getposition() Bj1.Getdepartment()endl; j1+; else if(flag=2) outfileflag Cj2.getname() Cj2.getsex() Cj2.G_age() Cj2.G_workday() Cj2.Getposition() Cj2.Getdepartment()endl; j2+; outfile.close(); void System:save() /初始化管理系统 int a; ifstream datafile; char name20; char sex6; int age; int workday; char position20; char department20; datafile.open(in.txt); if(!datafile) cerrtxt open error!a; datafilenamesexageworkdaypositiondepartment; switch(a) case 1: jingli A(name,sex,age,workday,position,department); /判断为经理导入经理类Bj1=A; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 9 页 - - - - - - - - - j1+; break; case 2: worker A(name,sex,age,workday,position,department); /判断为员工导入员工类Cj2=A; j2+; break; default: break; datafile.close(); void System:search1(int h,char ch20) /查找函数 int s=0; bool found=false; switch(h) case 1:while(sj1) /从经理数组查找 if(strcmp(Bs.getname(),ch)=0) Bs.Output(); found=true; break; s+; break; case 2:while(sj2) /从员工数组查找 if(strcmp(Cs.getname(),ch)=0) Cs.Output(); found=true; break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 9 页 - - - - - - - - - s+; break; if(!found) coutnntt 对不起,没有该职工!endl; /没有数据返回无 void System:search() /查找函数目录 int rev; char name20; int again=1; char t; while(again) coutttt 1. 查询一个经理endl; coutttt 2. 查询一个工人endl; coutrev; coutname; search1(rev,name); /具体实现函数coutt; coutendl; if(!(t=Y| t=y) again=0; Interface(); void System:Interface() /主目录函数 int rev; couttt *欢迎使用 ; cout*endl; couttt *职工管理信息系统; cout*endl; couttt 1.输入信息endl; couttt 2.查询信息并显示endl; couttt 3.退出endl; coutrev; switch(rev) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 9 页 - - - - - - - - - case 1:In_information(); break; case 2:search(); break; case 3:exit(0); int main() System sss; /调用系统类sss.Interface(); /具体实现return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 9 页 - - - - - - - - -