//全部源代码: #include<stdio.h> #include<string.h> #include<conio.h> #include <stdlib.h> #define MAX 100 char filename[20]; /*文件名*/ FILE *fp; int n; /*当前该厂人数*/ struct date /*时间结构体*/ { int year; int mouth; int day; } ; struct person /*员工信息结构体*/ { char name[10]; /*姓名*/ int age; /*年龄*/ char job[10]; /*工作*/ char sex[10]; /*性别*/ char address[20]; /*地址*/ char phone[10]; /*电话*/ struct date in_time; /*入厂时间*/ }t,worker[MAX]; /*录入模块*/ void input() {int i; system("cls");//system("cls"); printf("\n\n请输入文件名\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;i<n;i++) { printf("第%d个人的信息:\n",i+1); printf("姓名\n"); scanf("%s",worker[i].name); printf("年龄\n"); scanf("%d",&worker[i].age); printf("工作\n"); scanf("%s",worker[i].job); printf("性别\n"); scanf("%s",worker[i].sex); printf("地址\n"); scanf("%s",worker[i].address); printf("电话\n"); scanf("%s",worker[i].phone); printf("入厂年\n"); scanf("%d",&worker[i].in_time.year); printf("入厂月\n"); scanf("%d",&worker[i].in_time.mouth); printf("入厂日\n"); scanf("%d",&worker[i].in_time.day); } printf("录入完毕,按任意键返回主菜单\n"); getch(); for(i=0;i<n;i++) fprintf(fp,"%s %d %s %s %s %s %d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); fclose(fp); } /*输出模块*/ void output() { int i; if((fp=fopen(filename,"r"))==NULL) { printf(" 暂时未有任何信息,请按任意键返回主菜单进行信息录入\n"); getch(); exit(0); } system("cls"); printf(" 该厂的员工信息:\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); for(i=0;i<n;i++) { fscanf(fp,"%s %d %s %s %s %s %d-%d-%d",worker[i].name,&worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,&worker[i].in_time.year,&worker[i].in_time.mouth,&worker[i].in_time.day); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); } fclose(fp); printf(" 输出完毕,按任意键返回主菜单\n"); getch(); } /*保存模块*/ void save() { int i; if((fp=fopen(filename,"w"))==NULL) /*打开文件*/ { printf("\n 不能打开该文件!"); exit(0); } for(i=0;i<n;i++) fprintf(fp,"%s %d %s %s %s %s %d-%d-%d\n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); fclose(fp); } /*读取信息*/ void read_message() { int i; printf("输入文件名\n"); scanf("%s",filename); printf("\n请输入现有员工人数\n"); scanf("%d",&n); if((fp=fopen(filename,"r"))==NULL) { printf(" 暂时未有任何信息,请按任意键返回主菜单进行信息录入\n"); getch(); } for(i=0;i<n;i++) fscanf(fp,"%s %d %s %s %s %s %d-%d-%d",worker[i].name,&worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,&worker[i].in_time.year,&worker[i].in_time.mouth,&worker[i].in_time.day); fclose(fp); } /*修改模块*/ void modify() { int i,flag,choice; char ch,namekey[10]; flag=0; system("cls"); printf(" 开始修改\n"); do { printf("请输入要修改的员工姓名\n"); scanf("%s",namekey); for(i=0;i<n;i++) { if(strcmp(worker[i].name,namekey)==0) { printf("是否修改此人(y/n)\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); getchar(); /*接收回车*/ ch=getchar(); if(ch=='y') { printf(" ****您要修改那一项?***\n\n"); printf(" ***1,姓名***\n\n"); printf(" ***2,年龄***\n\n"); printf(" ***3,工作***\n\n"); printf(" ***4,性别***\n\n"); printf(" ***5,地址***\n\n"); printf(" ***6,电话***\n\n"); printf(" ***7,入厂年***\n\n"); printf(" ***8,入厂月***\n\n"); printf(" ***9,入厂日***\n\n"); printf(" 请选择(1-9)\n"); scanf("%d",&choice); switch(choice) { case 1: printf("输入修改后的姓名\n"); scanf("%s",worker[i].name); break; case 2: printf("输入修改后的年龄\n"); scanf("%d",&worker[i].age); break; case 3: printf("输入修改后的工作\n"); scanf("%s",worker[i].job); break; case 4: printf("输入修改后的性别\n"); scanf("%s",worker[i].sex); break; case 5: printf("输入修改后的地址\n"); scanf("%s",worker[i].address); break; case 6: printf("输入修改后的电话\n"); scanf("%s",worker[i].phone); break; case 7: printf("输入修改后的入厂年\n"); scanf("%d",&worker[i].in_time.year); break; case 8: printf("输入修改后的入厂月\n"); scanf("%d",&worker[i].in_time.mouth); break; case 9: printf("输入修改后的入厂日\n"); scanf("%d",&worker[i].in_time.day); break; } printf("修改后的信息\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); } else break; } else if(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 add() { int i,flag=0; char ch; system("cls"); printf("\n 开始添加新员工\n"); printf(" *----------------------------------*\n\n"); do { i=n; printf("\n 请输入添加职工的信息(姓名,年龄,工作,性别,地址,电话,入厂时间)\n"); printf("姓名\n"); scanf("%s",worker[i].name); printf("年龄\n"); scanf("%d", &worker[i].age); printf("工作\n"); scanf("%s",worker[i].job); printf(" 性别\n"); scanf("%s",worker[i].sex); printf("地址\n"); scanf("%s",worker[i].address); printf("电话\n"); scanf(" %s",worker[i].phone); printf("入厂年\n"); scanf("%d",&worker[i].in_time.year); printf("入厂月\n"); scanf("%d",&worker[i].in_time.mouth); printf("入厂日\n"); scanf("%d",&worker[i].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,namekey[10]; flag=0; system("cls"); printf("开始删除\n"); do { printf("请输入要删除员工的名字\n"); scanf("%s",namekey); for(i=0;i<n;i++) if(strcmp(worker[i].name,namekey)==0) /*查找此人*/ { printf("是否删除此人(y/n)\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); getchar(); /*接收回车*/ ch=getchar(); if(ch=='y') { for(;i<n;i++) worker[i]=worker[i+1]; n--; } else break; } else if(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"); printf("\n\n\n ****更新员工信息****\n\n"); printf(" 按1,添加员工信息\n\n"); printf(" 按2,删除员工信息\n\n"); printf(" 按3,修改员工信息\n\n"); 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 namekey[10]; j=0; system("cls"); printf(" 输入要查询的员工姓名\n"); scanf("%s",namekey); for(i=0;i<n;i++) if(strcmp(worker[i].name,namekey)==0) /*查找此人*/ { printf("---------员工信息------\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].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;i<n;i++) if(worker[i].age==agekey) { printf("-------员工信息------\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); } else j++; if(j==n) printf("此人不存在\n"); printf("按任意键返回主菜单\n"); getch(); } /*按工作查找*/ void job_cha() { int i,j; char jobkey[10]; j=0; system("cls"); printf("输入要查询的员工职务\n"); scanf("%s",jobkey); for(i=0;i<n;i++) if(strcmp(worker[i].job,jobkey)==0) { printf("-------员工信息------\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); } else j++; if(j==n) printf("此人不存在\n"); printf("按任意键返回主菜单\n"); getch(); } /*查询模块*/ void inquire() { int i; do { system("cls"); printf("\n\n\n ****查询员工信息*****\n\n"); printf(" ****1,按姓名查询*****\n\n"); printf(" ****2,按年龄查询*****\n\n"); printf(" ****3,按工作查询*****\n\n"); 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();break; case 0: break; } }while(i!=0); } /*排列模块*/ void line() { int i,j; system("cls"); printf("-------按年龄排序-------\n\n"); for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(worker[i].age>worker[j].age) { t=worker[i]; worker[i]=worker[j]; worker[j]=t; } printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); for(i=0;i<n;i++) printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].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;i<n;i++) if(worker[i].age==agekey) { printf("-------员工信息------\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); } else j++; if(j==n) printf("暂无该年龄段员工\n"); printf("按任意键返回主菜单\n"); getch(); } /*按职务统计*/ void count_job() { int i,j; char jobkey[10]; j=0; system("cls"); printf("输入要统计的员工职务\n"); scanf("%s",jobkey); for(i=0;i<n;i++) if(strcmp(worker[i].job,jobkey)==0) { printf("-------员工信息------\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); } else j++; if(j==n) printf("暂无该职务或该职务暂时无人\n"); printf("按任意键返回主菜单\n"); getch(); } /*按性别统计*/ void count_sex() { int i,j; char sexkey[10]; j=0; system("cls"); printf("输入要统计的员工性别\n"); scanf("%s",sexkey); for(i=0;i<n;i++) if(strcmp(worker[i].sex,sexkey)==0) { printf("-------员工信息------\n"); printf("姓名\t年龄\t工作\t性别\t地址\t电话\t入厂时间 \n"); printf("%s\t%d\t%s\t%s\t%s\t%s\t%d-%d-%d \n",worker[i].name,worker[i].age,worker[i].job,worker[i].sex,worker[i].address,worker[i].phone,worker[i].in_time.year,worker[i].in_time.mouth,worker[i].in_time.day); } else j++; if(j==n) printf("暂无该性别员工\n"); printf("按任意键返回主菜单\n"); getch(); } /*统计模块*/ void count() { int i; do { system("cls"); printf("\n\n\n ****统计员工信息****\n\n"); printf(" 按1,统计某年龄职工\n\n"); printf(" 按2,统计某职务员工\n\n"); printf(" 按3,统计某性别职工\n\n"); printf(" 按0,返回主菜单\n\n"); 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("\n\n *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*\n"); printf(" * *\n"); printf(" #----------------欢迎进入XXX企业员工管理系统-----------------#\n"); printf(" * *\n"); printf(" #----------------------按1,录入员工信息----------------------#\n"); printf(" * *\n"); printf(" #----------------------按2,更新员工信息----------------------#\n"); printf(" * *\n"); printf(" #----------------------按3,查询员工信息----------------------#\n"); printf(" * *\n"); printf(" #----------------------按4,排列员工信息----------------------#\n"); printf(" * *\n"); printf(" #----------------------按5,统计员工信息----------------------#\n"); printf(" * *\n"); printf(" #----------------------按6,输出员工信息----------------------#\n"); printf(" * *\n"); printf(" #-----------------------按0,退出系统-------------------------#\n"); printf(" * *\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("现有员工数:%d\n",n); printf("\n以上信息已保存!文件名为:%s\n",filename); }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。