首页 > 代码库 > 员工管理系统(完整版)
员工管理系统(完整版)
转载请注明出处:http://blog.csdn.net/u012860063
#include <stdio.h> #include <windows.h> #include <string.h> struct worker { int num; char name[20]; char zhicheng[10]; int wages; int reward; long birth; int salary; } work[500],work1; void menu(); void type_in(); void baocun(int); void scan(); void del(); void search(); void search_zhicheng(); void search_name(); void search_num(); void change(); void order(); void add(); void order_wages(); void order_name(); void order_num(); void menu() { printf("\n"); printf(" welcome to \n"); printf(" 职工信息管理系统 "); printf("******************************************************************************\n"); printf(" 1.录入职工信息\n"); printf(" 2.浏览职工信息\n"); printf(" 3.查询职工信息\n"); printf(" 4.删除职工信息\n"); printf(" 5.修改职工信息\n"); printf(" 6.职工信息排序\n"); printf(" 7.添加职工信息\n"); printf(" 8.退出\n"); printf("*******************************************************************************\n"); printf("\n"); } void main() { int n,f; while(1) { do { menu(); printf("请输入你需要操作的序号(1—8):\n"); scanf("%d",&n); if(n>=1&&n<=8) { f=1; break; } else { f=0; printf("您输入有误,请重新选择!"); } } while(f==0); switch(n) { case 1:printf(" 录入职工信息\n"); printf("\n"); type_in(); break; case 2:printf(" 浏览职工信息\n"); printf("\n");system("cls"); scan(); break; case 3:printf(" 查询职工信息\n"); printf("\n"); system("cls"); search(); break; case 4:printf(" 删除职工信息\n"); printf("\n"); system("cls"); del(); break; case 5:printf(" 修改职工信息\n"); printf("\n"); system("cls"); change(); break; case 6:printf(" 职工信息排序\n"); printf("\n"); system("cls"); order(); break; case 7:printf(" 添加职工信息\n"); printf("\n"); system("sls"); add(); break; case 8:goto loop; default :break; } } loop: system("cls"); printf("\n\n\n\n\n\n----------谢谢使用!---------\n\n\n\n\n\n"); } void type_in() { int i,m; printf("请输入需要创建信息的职工人数(1--500):\n"); scanf("%d",&m); for (i=0;i<m;i++) { printf("请输入职工号: "); scanf("%d",&work[i].num); printf("\n"); printf("请输入姓名: "); scanf("%s",work[i].name); getchar(); printf("请输入职称: "); scanf("%s",&work[i].zhicheng); printf("请输入基本工资: "); scanf("%d",&work[i].wages); printf("请输入奖金: "); scanf("%d",&work[i].reward); printf("请输入生日(格式如19900101): "); scanf("%d",&work[i].birth); work[i].salary=work[i].wages + work[i].reward; getchar();system("cls"); printf("\n一个职工的信息档案创建完毕!请输入下一个职工的信息\n"); printf("\n"); } baocun(m); } void baocun(int m) { int i; FILE *fp; if ((fp=fopen("E:\\worker_list.txt","wb"))==NULL) { printf ("此文件不能打开\n"); exit(0); } for (i=0;i<m;i++) if (fwrite(&work[i],sizeof(struct worker),1,fp)!=1) printf("file write error\n"); fclose(fp); } int load() { FILE*fp; int i=0; if((fp=fopen("E:\\worker_list.txt","rb"))==NULL) { printf ("cannot open file\n"); exit(0); } else { do { fread(&work[i],sizeof(struct worker),1,fp); i++; } while(feof(fp)==0); } fclose(fp); return(i-1); } void scan() { int i; int m=load(); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); for(i=0;i<m;i++) printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[i].num,work[i].name, work[i].zhicheng,work[i].wages,work[i].reward,work[i].salary,work[i].birth); printf("按任意键继续\n"); getchar(); getchar(); system("cls"); } void del() { int m=load(); int i,j,n,t,f; char name1[10]; printf("\n 原来的职工信息:\n"); scan(); printf("\n"); printf("请输入要删除的职工的姓名:\n"); scanf("%s",name1); for(f=1,i=0;f&&i<m;i++) { if(strcmp(work[i].name,name1)==0) { printf("\n已找到此人,原始记录为:\n"); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[i].num,work[i].name, work[i].zhicheng,work[i].wages,work[i].reward,work[i].salary,work[i].birth); printf("\n确实要删除此人信息请按1,不删除请按0\n"); scanf("%d",&n); if(n==1) { for(j=i;j<m-1;j++) { work[j]=work[j+1]; } f=0; } } } if(!f) m=m-1; else printf("\n对不起,查无此人!\n"); printf("\n 浏览删除后的所有职工信息:\n"); baocun(m); scan(); printf("\n继续删除请按1,不再删除请按0\n"); scanf("%d",&t); switch(t) { case 1:del();break; case 0:break; default :break; } system("cls"); } void search() { int t,f; do { printf("\n按姓名查询请按1 按职称查询请按2 按职工号查询请按3 进入主函数按4\n"); scanf("%d",&t); if(t>=1&&t<=4) { f=1; break; } else { f=0; printf("您输入有误,请重新选择!"); } } while(f==0); system("cls"); while(f==1) { switch(t) { case 1:printf("按姓名查询\n"); search_name();break; case 2:printf("按职称查询\n"); search_zhicheng();break; case 3:printf("按职工号查询\n"); search_num();break; case 4:main();break; default:break; } system("cls"); } } void search_name() { char name1[10]; int i,t; int m=load(); printf("请输入要查找的姓名:\n"); scanf("%s",name1); for(i=0;i<m;i++) if(strcmp(name1,work[i].name)==0) { printf("\n已找到此人,其记录为:\n"); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[i].num,work[i].name, work[i].zhicheng,work[i].wages,work[i].reward,work[i].salary,work[i].birth); break; } if(i==m) printf("\n对不起,查无此人\n"); printf("\n"); printf("返回查询函数请按1,继续查询职工号请按2\n"); scanf("%d",&t); switch(t) { case 1:search();break; case 2: break; default:break; } } void search_zhicheng() { char zhicheng1[10]; int i,t; int m=load(); printf("请输入要查找的职称:\n"); scanf("%s",zhicheng1); for(i=0;i<m;i++) if(strcmp(zhicheng1,work[i].zhicheng)==0) { printf("\n已找到此人,其记录为:\n"); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[i].num,work[i].name, work[i].zhicheng,work[i].wages,work[i].reward,work[i].salary,work[i].birth); break; } if(i==m) printf("\n对不起,查无此人\n"); printf("\n"); printf("返回查询函数请按1,继续查询职工号请按2\n"); scanf("%d",&t); switch(t) { case 1:search();break; case 2: break; default:break; } } void search_num() { int num; int i,t; int m=load(); printf("请输入要查找的职工号:\n"); scanf("%d",&num); for(i=0;i<m;i++) if(num==work[i].num) { printf("\n已找到此人,其记录为:\n"); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[i].num,work[i].name, work[i].zhicheng,work[i].wages,work[i].reward,work[i].salary,work[i].birth); break; } if(i==m) printf("\n对不起,查无此人\n"); printf("\n"); printf("返回查询函数请按1,继续查询职工号请按2\n"); scanf("%d",&t); switch(t) { case 1:search();break; case 2: break; default:break; } } void change() { int num; char name[20]; char zhicheng[10]; int wages; int reward; int birth; int salary; int b,c,i,n,t,f; int m=load(); printf("\n 原来的职工信息:\n"); scan(); printf("\n"); printf("请输入要修改的职工的姓名:\n"); scanf("%s",name); for(f=1,i=0;f&&i<m;i++) { if(strcmp(work[i].name,name)==0) { printf("\n已找到此人,原始记录为:\n"); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[i].num,work[i].name, work[i].zhicheng,work[i].wages,work[i].reward,work[i].salary,work[i].birth); printf("\n确实要修改此人信息请按1 不修改请按0\n"); scanf("%d",&n); if(n==1) { printf("\n需要进行修改的选项\n 1.职工号 2.姓名 3.职称 4.基本工资 5.奖金 6.生日 7.实际工资\n"); printf("请输入你想修改的那一项序号:\n"); scanf("%d",&c); if(c>7||c<1) printf("\n选择错误,请重新选择!\n"); } f=0; } } if(f==1) printf("\n对不起,查无此人!\n"); do { switch(c) { case 1:printf("职工号改为: "); scanf("%d",&num); work[i-1].num=num; break; case 2:printf("姓名改为: "); scanf("%s",name); strcpy(work[i-1].name,name); break; case 3:printf("职称改为"); scanf("%s",zhicheng); strcpy(work[i-1].zhicheng,zhicheng); break; case 4:printf("基本工资改为: "); scanf("%d",&wages); work[i-1].wages=wages; break; case 5:printf("奖金改为: "); scanf("%d",&reward); work[i-1].reward=reward; break; case 6:printf("生日改为: "); scanf("%ld",&birth); work[i-1].birth=birth; break; case 7:printf("实际工资改为: "); scanf("%d",&salary); work[i-1].salary=salary; break; } printf("\n"); printf("\n是否确定所修改的信息?\n 是 请按1 \n不,重新修改 请按2: \n"); scanf("%d",&b); } while(b==2); printf("\n浏览修改后的所有职工信息:\n"); printf("\n"); baocun(m); scan(); printf("\n继续修改请按1,不再修改请按0\n"); scanf("%d",&t); switch(t) { case 1:change();break; case 0:break; default :break; } system("cls"); } void order() { int k,f; do { printf("\n按姓名排序请按1 按基本工资排序请按2 按职工号排序请按3 进入主函数按4\n"); scanf("%d",&k); if(k>=1&&k<=4) { f=1;break; } else { f=0; printf("您输入有误,请重新选择!"); } } while(f==0);system("cls"); while(f==1) { switch(k) { case 1:printf("\n按姓名排序为(字母由小到大排列):\n"); order_name();break; case 2:printf("\n按基本工资排序为(由高到低排列):\n"); order_wages();break; case 3:printf("\n按职工号排序为(由小到大排列):\n"); order_num();break; case 4:system("cls"); main();break; default:break; } system("cls"); } } void order_name() { int i,j,k; int m=load(); for(i=0;i<m-1;i++) for(j=0;j<m-1-i;j++) if(strcmp(work[j].name,work[j+1].name)>0) { work1=work[j];work[j]=work[j+1];work[j+1]=work1; } baocun(m); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); for(j=0;j<m;j++) printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[j].num,work[j].name, work[j].zhicheng,work[j].wages,work[j].reward,work[j].salary,work[j].birth); printf("返回排序函数请按1,返回主菜单请按2\n"); scanf("%d",&k); switch(k) { case 1:order();break; case 2:system("cls");main();break; default:break; } system("cls"); } void order_wages() { int i,k,j; int m=load(); for(i=0;i<m-1;i++) for(j=0;j<m-1-i;j++) if(work[j].wages<work[j+1].wages) { work1=work[j];work[j]=work[j+1];work[j+1]=work1; } baocun(m); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); for(j=0;j<m;j++) printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[j].num,work[j].name, work[j].zhicheng,work[j].wages,work[j].reward,work[j].salary,work[j].birth); printf("返回排序函数请按1,返回主菜单请按2\n"); scanf("%d",&k); switch(k) { case 1:order();break; case 2:system("cls"); main();break; default:break; } system("cls"); } void order_num() { int i,j,k; int m=load(); for(i=0;i<m-1;i++) for(j=0;j<m-1-i;j++) if(work[j].num<work[j+1].num) { work1=work[j];work[j]=work[j+1];work[j+1]=work1; } baocun(m); printf("\n职工号\t姓名\t职称\t基本工资\t奖金\t实际工资\t生日 \n"); for(j=0;j<m;j++) printf("\n %d\t%s\t %s\t %d \t%d\t %d\t %ld\n",work[j].num,work[j].name, work[j].zhicheng,work[j].wages,work[j].reward,work[j].salary,work[j].birth); printf("返回排序函数请按1,返回主菜单请按2\n"); scanf("%d",&k); switch(k) { case 1:order();break; case 2:system("cls"); main();break; default:break; } system("cls"); } void add() { int n=load(); int i,m; printf("请输入需要添加信息的职工人数\n"); scanf("%d",&m); for (i=n;i<m+n;i++) { printf("请输入职工号: "); scanf("%d",&work[i].num); printf("\n"); printf("请输入姓名: "); scanf("%s",work[i].name); printf("请输入职称: "); scanf("%s",&work[i].zhicheng); printf("请输入基本工资: "); scanf("%d",&work[i].wages); printf("请输入奖金: "); scanf("%d",&work[i].reward); printf("请输入生日(格式如19900101): "); scanf("%d",&work[i].birth); getchar(); system("cls"); printf("\n一个职工的信息档案添加完毕!请输入下一个职工的信息\n"); work[i].salary=work[i].wages + work[i].reward; printf("\n"); } baocun(m+n); system("cls"); printf("添加职工档案完成。\n这时库存信息为:\n"); scan(); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。