1、全部源代码:#include#include#include#include #define MAX 100char filename20; /*文件名*/FILE *fp;int n; /*目前该厂人数*/struct date /*时间结构体*/ int year;int mouth;int day; ;struct person /*职员信息结构体*/ char name10; /*姓名*/int age; /*年纪*/char job10; /*工作*/char sex10; /*性别*/char address20; /*地址*/char phone10; /*电话*/struct
2、date in_time; /*入厂时间*/t,workerMAX;/*录入模块*/void input()int i;system(cls);/system(cls);printf(nn请输入文件名n);scanf(%s,filename);printf(开始输入职员信息n);printf(n请输入现有职员人数n);scanf(%d,&n);if(fp=fopen(filename,w)=NULL) printf(不能建立!n);exit(0);for(i=0;in;i+) printf(第%d个人信息:n,i+1);printf(姓名n);scanf(%s,workeri.name);pr
3、intf(年纪n);scanf(%d,&workeri.age);printf(工作n);scanf(%s,workeri.job);printf(性别n);scanf(%s,workeri.sex);printf(地址n);scanf(%s,workeri.address);printf(电话n);scanf(%s,workeri.phone);printf(入厂年n);scanf(%d,&workeri.in_time.year);printf(入厂月n);scanf(%d,&workeri.in_time.mouth);printf(入厂日n);scanf(%d,&workeri.in_
4、time.day);printf(录入完成,按任意键返回主菜单n);getch();for(i=0;in;i+)fprintf(fp,%s %d %s %s %s %s %d-%d-%dn,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);fclose(fp);/*输出模块*/void output() int i;if(fp=fopen(filename,r)
5、=NULL) printf( 临时未有任何信息,请按任意键返回主菜单进行信息录入n);getch();exit(0);system(cls);printf( 该厂职员信息:n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);for(i=0;in;i+) fscanf(fp,%s %d %s %s %s %s %d-%d-%d,workeri.name,&workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,&workeri.in_time.year,&workeri.in_time.mouth,&
6、workeri.in_time.day);printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);fclose(fp);printf( 输出完成,按任意键返回主菜单n);getch();/*保留模块*/void save() int i;if(fp=fopen(filename,w)=NULL)
7、/*打开文件*/ printf(n 不能打开该文件!);exit(0);for(i=0;in;i+)fprintf(fp,%s %d %s %s %s %s %d-%d-%dn,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);fclose(fp);/*读取信息*/void read_message() int i;printf(输入文件名n);scanf(%s
8、,filename);printf(n请输入现有职员人数n);scanf(%d,&n);if(fp=fopen(filename,r)=NULL) printf( 临时未有任何信息,请按任意键返回主菜单进行信息录入n);getch();for(i=0;in;i+)fscanf(fp,%s %d %s %s %s %s %d-%d-%d,workeri.name,&workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,&workeri.in_time.year,&workeri.in_time.mouth,&worke
9、ri.in_time.day);fclose(fp);/*修改模块*/void modify() int i,flag,choice; char ch,namekey10;flag=0;system(cls);printf( 开始修改n);doprintf(请输入要修改职员姓名n);scanf(%s,namekey);for(i=0;in;i+) if(strcmp(workeri.name,namekey)=0) printf(是否修改此人(y/n)n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%st%st%st%st%d-%d-%d n,
10、workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);getchar(); /*接收回车*/ch=getchar();if(ch=y) printf( *您要修改那一项?*nn);printf( *1,姓名*nn);printf( *2,年纪*nn);printf( *3,工作*nn);printf( *4,性别*nn);printf( *5,地址*nn);prin
11、tf( *6,电话*nn);printf( *7,入厂年*nn);printf( *8,入厂月*nn);printf( *9,入厂日*nn);printf( 请选择(1-9)n);scanf(%d,&choice);switch(choice) case 1: printf(输入修改后姓名n);scanf(%s,workeri.name); break;case 2: printf(输入修改后年纪n);scanf(%d,&workeri.age); break;case 3: printf(输入修改后工作n);scanf(%s,workeri.job); break;case 4: print
12、f(输入修改后性别n);scanf(%s,workeri.sex); break;case 5: printf(输入修改后地址n);scanf(%s,workeri.address); break;case 6: printf(输入修改后电话n);scanf(%s,workeri.phone); break;case 7: printf(输入修改后入厂年n);scanf(%d,&workeri.in_time.year); break;case 8: printf(输入修改后入厂月n);scanf(%d,&workeri.in_time.mouth); break;case 9: printf
13、(输入修改后入厂日n);scanf(%d,&workeri.in_time.day); break;printf(修改后信息n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);else break;elseif(i=n)
14、printf(此人不存在n);printf(n是否继续输入(y/n)n);getchar(); /*接收回车*/ch=getchar();if(ch=y) printf(继续n);flag=1;else flag=0;while(flag=1);printf(修改完成,按任意键返回主菜单n) ;getch();/*添加模块*/void add() int i,flag=0; char ch;system(cls);printf(n 开始添加新职员n);printf( *-*nn);do i=n;printf(n 请输入添加职员信息(姓名,年纪,工作,性别,地址,电话,入厂时间)n);print
15、f(姓名n);scanf(%s,workeri.name);printf(年纪n);scanf(%d, &workeri.age);printf(工作n);scanf(%s,workeri.job);printf( 性别n);scanf(%s,workeri.sex);printf(地址n);scanf(%s,workeri.address);printf(电话n);scanf( %s,workeri.phone);printf(入厂年n);scanf(%d,&workeri.in_time.year);printf(入厂月n);scanf(%d,&workeri.in_time.mouth)
16、;printf(入厂日n);scanf(%d,&workeri.in_time.day);n+;printf(n添加成功!是否继续输入(y/n)n);getchar(); /*接收回车*/ch=getchar();if(ch=y) printf(继续n);flag=1;else flag=0;while(flag=1);printf(添加完成,按任意键返回主菜单n) ;getch();/*删除模块*/void del() int i,flag; char ch,namekey10;flag=0;system(cls);printf(开始删除n);do printf(请输入要删除职员名字n);s
17、canf(%s,namekey);for(i=0;in;i+)if(strcmp(workeri.name,namekey)=0) /*查找此人*/ printf(是否删除此人(y/n)n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_ti
18、me.day);getchar(); /*接收回车*/ch=getchar();if(ch=y) for(;in;i+)workeri=workeri+1;n-;else break;elseif(i=n)printf(此人不存在n);printf(n是否继续输入(y/n)n);getchar(); /*接收回车*/ch=getchar();if(ch=y) printf(继续n);flag=1;else flag=0;while(flag=1);printf(操作完成,按任意键返回主菜单n) ;getch();/*更新模块*/void renew() int i;do system(cls)
19、;printf(nnn *更新职员信息*nn);printf( 按1,添加职员信息nn);printf( 按2,删除职员信息nn);printf( 按3,修改职员信息nn);printf( 按0,返回主菜单n);printf( 请选择(0-3)n);scanf(%d,&i);switch(i) case 1: add(); break;case 2: del(); break;case 3: modify(); break;case 0: break;while(i!=0);save();/*按姓名查找*/void name_cha() int i,j; char namekey10;j=0;
20、system(cls);printf( 输入要查询职员姓名n);scanf(%s,namekey);for(i=0;in;i+)if(strcmp(workeri.name,namekey)=0) /*查找此人*/ printf(-职员信息-n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri
21、.in_time.mouth,workeri.in_time.day);else j+;if(j=n)printf(此人不存在n);printf(按任意键返回主菜单n);getch();/*按年纪查找*/void age_cha() int i,j; int agekey;j=0;system(cls);printf( 输入要查询职员年纪n);scanf(%d,&agekey);for(i=0;in;i+)if(workeri.age=agekey) printf(-职员信息-n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%st%st%st%
22、st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);else j+;if(j=n)printf(此人不存在n);printf(按任意键返回主菜单n);getch();/*按工作查找*/void job_cha() int i,j; char jobkey10;j=0;system(cls);printf(输入要查询职员职务n);scanf
23、(%s,jobkey);for(i=0;in;i+)if(strcmp(workeri.job,jobkey)=0) printf(-职员信息-n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);else j+;if(j=
24、n)printf(此人不存在n);printf(按任意键返回主菜单n);getch();/*查询模块*/void inquire() int i;do system(cls);printf(nnn *查询职员信息*nn);printf( *1,按姓名查询*nn);printf( *2,按年纪查询*nn);printf( *3,按工作查询*nn);printf( *0,返回主菜单n);printf( 请选择(0-3)n);scanf(%d,&i);switch(i) case 1: name_cha();break;case 2: age_cha(); break;case 3: job_cha
25、();break;case 0: break;while(i!=0);/*排列模块*/void line() int i,j;system(cls);printf(-按年纪排序-nn);for(i=0;in-1;i+)for(j=i+1;jworkerj.age) t=workeri;workeri=workerj;workerj=t;printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);for(i=0;in;i+)printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex
26、,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);printf(按任意键返回主菜单n);getch();/*按年纪统计*/void count_age() int i,j; int agekey;j=0;system(cls);printf( 输入要统计职员年纪n);scanf(%d,&agekey);for(i=0;in;i+)if(workeri.age=agekey) printf(-职员信息-n);printf(姓名t年纪t工作t性别t地址t电话t
27、入厂时间 n);printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);else j+;if(j=n)printf(暂无该年纪段职员n);printf(按任意键返回主菜单n);getch();/*按职务统计*/void count_job() int i,j; char jobkey10;j=0;
28、system(cls);printf(输入要统计职员职务n);scanf(%s,jobkey);for(i=0;in;i+)if(strcmp(workeri.job,jobkey)=0) printf(-职员信息-n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%st%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mout
29、h,workeri.in_time.day);else j+;if(j=n)printf(暂无该职务或该职务临时无人n);printf(按任意键返回主菜单n);getch();/*按性别统计*/void count_sex() int i,j; char sexkey10;j=0;system(cls);printf(输入要统计职员性别n);scanf(%s,sexkey);for(i=0;in;i+)if(strcmp(workeri.sex,sexkey)=0) printf(-职员信息-n);printf(姓名t年纪t工作t性别t地址t电话t入厂时间 n);printf(%st%dt%s
30、t%st%st%st%d-%d-%d n,workeri.name,workeri.age,workeri.job,workeri.sex,workeri.address,workeri.phone,workeri.in_time.year,workeri.in_time.mouth,workeri.in_time.day);else j+;if(j=n)printf(暂无该性别职员n);printf(按任意键返回主菜单n);getch();/*统计模块*/void count() int i;do system(cls);printf(nnn *统计职员信息*nn);printf( 按1,统
31、计某年纪职员nn);printf( 按2,统计某职务职员nn);printf( 按3,统计某性别职员nn);printf( 按0,返回主菜单nn);printf( 请选择(0-3):n);scanf(%d,&i);switch(i) case 1: count_age(); break;case 2: count_job(); break;case 3: count_sex(); break;case 0: break;while(i!=0);/*主函数*/main() int choice;read_message();do system(cls);printf(nn *#*#*#*#*#*
32、#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*n);printf( #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#n);printf( * *n);printf( #-欢迎进入王氏企业职员管理系统-#n);printf( * *n);printf( #-按1,录入职员信息-#n);printf( * *n);printf( #-按2,更新职员信息-#n);printf( * *n);printf( #-按3,查询职员信息-#n);printf( * *n);
33、printf( #-按4,排列职员信息-#n);printf( * *n);printf( #-按5,统计职员信息-#n);printf( * *n);printf( #-按6,输出职员信息-#n);printf( * *n);printf( #-按0,退出系统-#n);printf( * *n);printf( #*#*#*#*#*#*# 制作者:王增 QQ: *#*#*#*#n);printf( #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#n);scanf(%d,&choice);switch(choice) case 1: input(); break;case 2: renew(); break;case 3: inquire(); break;case 4: line(); break;case 5: count(); break;case 6: output(); break;case 0: break;while(choice!=0);save();printf(现有职员数:%dn,n);printf(n以上信息已保留!文件名为:%sn,filename);
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100