当前位置:文档之家› 一个项目设计:职工信息管理系统

一个项目设计:职工信息管理系统

#include <stdio.h>#include <string.h>#include <stdlib.h>#include <time.h>#include <conio.h>#define N 100struct employee//职工基本情况{int num; //工号char name[10]; //姓名int sex; //性别int position; //职位int age; //年龄int cult; //学历int salary; //工资int state; //健康情况long tel; //联系电话char adr[50]; //住址}em[N];int num[N]={0};struct employee newem;void mainmenu(); //主菜单void input(); //输入模块void display(); //显示模块void del(); //删除模块void add(); //添加模块void count(); //统计模块void change(); //修改模块int changeposition(); //修改职位int changecult(); //修改学历int changesalary(); //修改工资int changestate(); //修改身体状况void changmany(); //修改多项信息void print(); //打印函数void select(); //查询模块void numselect(); //按工号查询void nameselect(); //按姓名查询void cultselect(); //按学历查询void positionselect(); //按职位查询•2010-7-11 11:46•回复••LUZIF200826•2位粉丝•2楼void stateselect(); //按身体状况查询void sexselect(); //按性别查询void ageselect(); //按年龄区间查询void salaryselect(); //按工资区间查询void paixu(); //排序模块void numpx(); //按工号排序void cultpx(); //按学历排序void positionpx(); //按职位排序void statepx(); //按身体状况排序void agepx(); //按年龄排序void salarypx(); //按工资排序void main() //主函数{char password[7]="1";char s[7];int flag=0;int n=3;system("mode con: lines=100 cols=120 ");do{printf("请你输入密码:\n");scanf("%s",s);if(!strcmp(s,password)) //若密码正确{printf("恭喜你成功登陆了\n\n\n");flag=1;break;}else{printf("输入有错误请重新输入:\n");n--;}}while(n>0);if(!flag){printf("你的输入次数已到再见\n");•2010-7-11 11:46•回复••LUZIF200826•2位粉丝•3楼exit(0);}printf("请按任意键继续!\n");getch();mainmenu();}void mainmenu() //主菜单{int choicemanage=0;while(1){system("cls");printf("\t\t欢迎进入职工信息管理系统\n");printf("\t\t============================\n");printf("\t\t请你选择操作类型:\n");printf("\t\t1输入职工信息\n");printf("\t\t2显示职工信息\n");printf("\t\t3查询职工信息\n");printf("\t\t4修改职工信息\n");printf("\t\t5追加一个职工信息\n");printf("\t\t6删除一个职工信息\n");printf("\t\t7统计职工信息\n");printf("\t\t8对职工信息进行排序\n");printf("\t\t0退出\n");printf("\t\t===========================\n");scanf("%d",&choicemanage);switch(choicemanage){case 1:input(); //输入职工信息break;case 2:display(); //显示职工信息break;case 3:select(); //查询职工信息break;case 4:change(); //修改职工信息break;case 5:add(); //追加一个职工信息break;case 6:del(); //删除一个职工信息•2010-7-11 11:46•回复••LUZIF200826•2位粉丝•4楼break;case 7:count(); //统计职工信息break;case 8:paixu(); //对职工信息进行排序break;case 0:printf("谢谢你的使用再见\n");exit(0);default:printf("你的输入有错请重新输入\n");}}}void input() //输入模块{FILE *fp;int k,j,flag=0,i=0;char choice;system("cls");if((fp=fopen("employee.txt","w"))==NULL)exit(0);srand(time(NULL));while(1){i++;system("cls");printf("第%d个职工\n",i);printf("\n");do{em[i].num=rand()%6000+2000; //自动生成工号for(j=0;num[j];j++){if(num[j]==em[i].num){flag=1;break;}}if(flag!=1){num[i]=em[i].num;break;}}while(1);•2010-7-11 11:46•回复••LUZIF200826•2位粉丝•5楼printf("工号:%d\n",num[i]);printf("请输入姓名:\n"); //输入姓名scanf("%s",em[i].name);printf("\n");do{printf("请选择性别以1为男2为女:\n"); //输入性别scanf("%d",&k);if(k>=1&&k<=2){em[i].sex=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");do{printf("请选择职位1.董事长2.总经理3.副总经理4.经理5.副经理6.秘书7.技术员8.领班9.普通员工:\n");//输入职位scanf("%d",&k);if(k>=1&&k<=9){em[i].position=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入年龄:");scanf("%d",&em[i].age);printf("\n");do{printf("请选择文化程度1为专家2为博士3为硕士4为学士5为其他:\n");//输入文化程度scanf("%d",&k);if(k>=1&&k<=5){em[i].cult=k;break;•2010-7-11 11:46•回复••LUZIF200826•2位粉丝•6楼}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入工资:\n");//输入工资scanf("%d",&em[i].salary);printf("\n");do{printf("请你选择身体情况1好2为一般3为差:\n");//身体情况scanf("%d",&k);if(k>=1&&k<=3){em[i].state=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入联系电话:");scanf("%ld",&em[i].tel);printf("\n");printf("请输入地址:");scanf("%s",em[i].adr);printf("\n");fwrite(&em[i],sizeof(struct employee),1,fp);printf("是否继续输入?(y/n)\n");scanf("%s",&choice);if(choice=='n'||choice=='N')break;}fclose(fp);if((fp=fopen("num.txt","w"))==NULL)exit(0);for(i=0;num[i];i++)fwrite(&num[i],sizeof(int),1,fp);fclose(fp);printf("输入完毕,任意键返回\n");getch();}void display() //显示职工信息{FILE *fp;int i;system("cls");if((fp=fopen("employee.txt","r+"))==NULL){printf("文件不存在或为空,请先输入员工信息!\n");mainmenu();}printf("输出结果:\n");printf("工号\t姓名\t年龄\t性别\t职位\t \t文化程度\t身体情况\t工资\t电话\t住址\n");for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++){print(em[i]);}printf("完毕按任意键返回\n");getch();fclose(fp);}•2010-7-11 11:46•回复•KLZ毕业7楼一大伙作业党要幸福的笑了……•阿宾和白洁•289位粉丝••2010-7-11 11:50 •回复••LUZIF200826•2位粉丝•8楼void change() //修改模块{FILE *fp;int i,k,l=0;int chnum;int choicechange;system("cls");printf("请你输入要修改的人的工号:\n");scanf("%d",&chnum);if((fp=fopen("employee.txt","r+"))==NULL){printf("不能够打开这个文件\n");exit(0);}for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++) ;k=i;fclose(fp);if((fp=fopen("employee.txt","w+"))==NULL){printf("不能够打开这个文件\n");exit(0);}for(i=0;i<k;i++){if(chnum==em[i].num){l=1;printf("这是你要修改的人的信息\n");printf("工号\t姓名\t年龄\t性别\t职位\t \t文化程度\t身体情况\t工资\t电话\t住址\n");print(em[i]);printf("------------------------------------------------------------\n");printf("请选择要修改的部分:\n");printf("\t\t===============================\n");printf("\t\t1仅修改职位\n");printf("\t\t2仅修改文化程度\n");printf("\t\t3仅修改工资\n");printf("\t\t4仅修改身体情况\n");printf("\t\t5修改多项\n");printf("\t\t0返回主菜单\n");printf("\t\t============================\n");•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•9楼printf("请选择\n");scanf("%d",&choicechange);switch(choicechange){case 1:em[i].position=changeposition();break;case 2:em[i].cult=changecult();break;case 3:em[i].salary=changesalary();break;case 4:em[i].state=changestate();break;case 5:newem=em[i];changmany();em[i]=newem;break;case 0:mainmenu();default :printf("输入有错误");}}fwrite(&em[i],sizeof(struct employee),1,fp);}fclose(fp);if(l==0){printf("该员工不存在,请查证后再输入!\n");select();}•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•10楼elseprintf("操作完成按任意键返回主菜单\n");getch();}int changeposition(){int newposition;printf("请选择新职位1为董事长2为总经理3为副总经理4为经理5为副经理6为秘书7为技术员8为领班9为普通员工:\n");scanf("%d",&newposition);return(newposition);}int changecult(){int newcult;printf("请选择新的文凭1为专家2为博士3为硕士4为学士5为其他:\n");scanf("%d",&newcult);return(newcult);}int changesalary(){int newsalary;printf("请输入新的工资:\n");scanf("%d",&newsalary);return(newsalary);}int changestate(){int newstate;printf("请选择现在的身体情况1好2为一般3为差:\n");scanf("%d",&newstate);return(newstate);}void changmany(){int k;system("cls");printf("请依次输入该员工的新信息\n");do{printf("请选择职位1.董事长2.总经理3.副总经理4.经理5.副经理6.秘书7.技术员8.领班9.普通员工:\n");//输入职位scanf("%d",&k);if(k>=1&&k<=9){newem.position=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入年龄:");scanf("%d",&newem.age);printf("\n");do{printf("请选择文化程度1为专家2为博士3为硕士4为学士5为其他:\n");//输入文化程度scanf("%d",&k);if(k>=1&&k<=5){newem.cult=k;•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•11楼break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入工资:\n");//输入工资scanf("%d",&newem.salary);printf("\n");do{printf("请你选择身体情况1好2为一般3为差:\n");//身体情况scanf("%d",&k);if(k>=1&&k<=3){newem.state=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入联系电话:");scanf("%ld",&newem.tel);printf("\n");printf("请输入地址:");scanf("%s",newem.adr);printf("\n");}void add()//追加一个职工信息{struct employee emp;FILE *fp;int l,k,j,flag=0,i=0;system("cls");if((fp=fopen("num.txt","r+"))==NULL)exit(0);for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++);l=i;fclose(fp);if((fp=fopen("employee.txt","ab+"))==NULL){printf("不能够打开这个文件\n");getch();exit(0);}printf("请你输入新人的内容:\n");srand(time(NULL));do{emp.num=rand()%6000+2000; //自动生成工号for(j=0;num[j];j++){if(num[j]==emp.num)•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•12楼{flag=1;break;}}if(flag!=1){num[l]=emp.num;l++;break;}}while(1);printf("请输入姓名:\n"); //输入姓名scanf("%s",);printf("\n");do{printf("请选择性别以1为男2为女:\n"); //输入性别scanf("%d",&k);if(k>=1&&k<=2){emp.sex=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");do{printf("请选择职位1.董事长2.总经理3.副总经理4.经理5.副经理6.秘书7.技术员8.领班9.普通员工:\n");//输入职位scanf("%d",&k);if(k>=1&&k<=9){emp.position=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入年龄:");scanf("%d",&emp.age);printf("\n");do{printf("请选择文化程度1为专家2为博士3为硕士4为学士5为其他:\n");//输入文化程度•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•13楼scanf("%d",&k);if(k>=1&&k<=5){emp.cult=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入工资:\n");//输入工资scanf("%d",&emp.salary);printf("\n");do{printf("请你选择身体情况1好2为一般3为差:\n");//身体情况scanf("%d",&k);if(k>=1&&k<=3){emp.state=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入联系电话:");scanf("%ld",&emp.tel);printf("\n");printf("请输入地址:");scanf("%s",emp.adr);printf("\n");fwrite(&emp,sizeof(struct employee),1,fp);rewind(fp);fclose(fp);if((fp=fopen("num.txt","w+"))==NULL)exit(0);for(i=0;i<l;i++)fwrite(&num[i],sizeof(int),1,fp);fclose(fp);printf("插入完毕,按任意键返回\n");getch();}void del()//删除一个职工信息{int i=0,j=0,l=0,k,b;char choice;int delnum;FILE *fp;if((fp=fopen("employee.txt","r+"))==NULL){printf("文件为空,不能够打开\n");printf("按任意键返回\n");getch();•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•14楼mainmenu();}printf("请你输入要删除的人的工号:\n");//删除的职工的信息scanf("%d",&delnum);for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++) {if(em[i].num==delnum){j=i;l=1;}}k=i;fclose(fp);if(l==0){printf("该员工不存在!\n");mainmenu();}printf("你要删除的职工信息为:\n");printf("工号\t姓名\t年龄\t性别\t职位\t \t文化程度\t身体情况\t工资\t电话\t住址\n");print(em[j]);printf("是否真的删除该职工信息[y/n]\n");scanf("%s",&choice);if(choice=='n'||choice=='N'){printf("取消删除,按任意键返回主菜单!\n");getch();mainmenu();}if((fp=fopen("employee.txt","w+"))==NULL){printf("文件为空,不能够打开\n");printf("按任意键返回\n");getch();mainmenu();}for(i=0;i<k;i++){if(i!=j)fwrite(&em[i],sizeof(struct employee),1,fp);}fclose(fp);if((fp=fopen("num.txt","r+"))==NULL)exit(0);for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++);b=i;fclose(fp);if((fp=fopen("num.txt","w+"))==NULL)exit(0);for(i=0;i<k;i++){•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•15楼if(num[i]!=delnum)fwrite(&num[i],sizeof(int),1,fp);}fclose(fp);printf("删除成功,按任意键返回!\n");getch();}void count(){FILE *fp;int i=0;int num=0;//总人数统计int mnum=0,fnum=0;//性别人数统计int zjnum=0,bsnum=0,ssnum=0,xsnum=0,othernum=0;//学位人数统计int dsznum=0,zglnum=0,fzglnum=0,glnum=0,fglnum=0;//职位人数统计int mishunum=0,jsynum=0,lbnum=0,ygnum=0;system("cls");if((fp=fopen("employee.txt","r+"))==NULL){printf("不能够打开这个文件\n");exit(0);}do{fread(&em[i],sizeof(struct employee),1,fp);if(feof(fp))break;num++;if(em[i].sex==1) //性别统计mnum++;if(em[i].sex==2)fnum++;if(em[i].cult==1) //文凭统计zjnum++;if(em[i].cult==2)bsnum++;if(em[i].cult==3)ssnum++;if(em[i].cult==4)xsnum++;if(em[i].cult==5)othernum++;if(em[i].position==1) //职位统计dsznum++;if(em[i].position==2)zglnum++;•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•16楼if(em[i].position==3)fzglnum++;if(em[i].position==4)glnum++;if(em[i].position==5)fglnum++;if(em[i].position==6)mishunum++;if(em[i].position==7)jsynum++;if(em[i].position==8)lbnum++;if(em[i].position==9)ygnum++;i++;}while(1);printf("总人数为%d\n",num);printf("=======性别分类========\n");printf("男人数为%d\n",mnum);printf("女人数为%d\n",fnum);printf("========文凭分类========\n");printf("专家数为%d\n",zjnum);printf("博士数为%d\n",bsnum);printf("硕士数为%d\n",ssnum);printf("学士数为%d\n",xsnum);printf("其他的数为%d\n",othernum);printf("========职位分类===========\n");printf("董事长数为%d\n",dsznum);printf("总经理数为%d\n",zglnum);printf("副总经理数为%d\n",fzglnum);printf("经理数为%d\n",glnum);printf("副经理数为%d\n",fglnum);printf("秘书数为%d\n",mishunum);printf("技术员数为%d\n",jsynum);printf("领班人数为%d\n",lbnum);printf("普通员工数为%d\n",ygnum);printf("统计完毕,按任意键返回\n");getch();fclose(fp);}void select() //查询模块{int choice;system("cls");printf("请选择查询方式\n");printf("\t\t============================\n");printf("\t\t1按工号查询\n");printf("\t\t2按姓名查询\n");printf("\t\t3按学历查询\n");•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•17楼printf("\t\t4按职位查询\n");printf("\t\t5按身体状况查询\n");printf("\t\t6按性别查询\n");printf("\t\t7按年龄区间查询\n");printf("\t\t8按工资区间查询\n");printf("\t\t0返回主菜单\n");printf("\t\t============================\n"); printf("请选择\n");scanf("%d",&choice);switch(choice){case 1:numselect();break;case 2:nameselect();break;case 3:cultselect();break;case 4:positionselect();break;case 5:stateselect();break;case 6:sexselect();break;case 7:ageselect();break;case 8:salaryselect();break;case 0:mainmenu();break;default:printf("你的输入有错请重新输入\n");select();}}void numselect() //按工号查询{FILE *fp;int i=0;int quenum;if((fp=fopen("employee.txt","r"))==NULL) {printf("不能够打开文件\n");exit(0);}printf("请你输入要查询的人的工号\n");scanf("%d",&quenum);for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++){if(em[i].num==quenum) /*找到,并显示该职工记录*/•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•18楼{printf("工号\t姓名\t年龄\t性别\t职位\t \t 文化程度\t身体情况\t工资\t电话\t住址\n");print(em[i]);printf("查询完毕,按任意键返回\n");getch();fclose(fp);mainmenu();}}printf("没有这样的人,按任意键返回\n");getch();fclose(fp);}void nameselect() //按姓名查询{FILE *fp;int l=0,i=0;char ch;char quename[10];if((fp=fopen("employee.txt","r"))==NULL){printf("不能够打开文件\n");exit(0);}printf("请你输入要查询的人的姓名\n");scanf("%s",quename);printf("工号\t姓名\t年龄\t性别\t职位\t \t文化程度\t身体情况\t工资\t电话\t住址\n");for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++){if(strcmp(em[i].name,quename)==0) /*找到,并显示该职工记录*/{print(em[i]);l++;}}if(l==0)printf("没有这样的人!\n");elseprintf("查询完毕!共查找到%d条记录\n",l);fclose(fp);printf("按1返回上一级菜单,按其他键返回主菜单\n");ch=getch();switch(ch){case '1':select();break;default:mainmenu();•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•19楼}}void cultselect() //按学历查询{FILE *fp;int i=0;char ch;int k,l=0;if((fp=fopen("employee.txt","r"))==NULL){printf("不能够打开文件\n");exit(0);}printf("请选择要查询的人的学历:1为专家2为博士3为硕士4为学士5为其他\n");scanf("%d",&k);printf("工号\t姓名\t年龄\t性别\t职位\t \t文化程度\t身体情况\t工资\t电话\t住址\n");for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i+ +){if(em[i].cult==k) /*找到,并显示该职工记录*/{print(em[i]);l++;}}if(l==0){printf("没有这样的人!\n");getch();}elseprintf("共找到符合条件的%d个职工!\n",l);fclose(fp);printf("按1返回上一级菜单,按其他键返回主菜单\n");ch=getch();switch(ch){case '1':select();break;default:mainmenu();}}void positionselect() //按职位查询{FILE *fp;int i=0;char ch;int k,l=0;if((fp=fopen("employee.txt","r"))==NULL){printf("不能够打开文件\n");exit(0);}printf("请选择要查询的人的职位:1.董事长2.总经理3.副总经理4.经理5.副经理6.秘书7.技术员8.领班9.普通员工\ n");scanf("%d",&k);printf("工号\t姓名\t年龄\t性别\t职位\t \t文化程度\t身体情况\t工资\t电话\t住址\n");for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i+ +){if(em[i].position==k) /*找到,并显示该职工记录*/{print(em[i]);l++;}}if(l==0){printf("没有您所要查询的员工信息!\n");}elseprintf("共找到符合条件的%d个职工!\n");fclose(fp);printf("按1返回上一级菜单,按其他键返回主菜单\n");ch=getch();switch(ch){case '1':select();break;default:mainmenu();}}•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•21楼printf("请选择\n");scanf("%d",&choicechange);switch(choicechange){case 1:em[i].position=changeposition();break;case 2:em[i].cult=changecult();break;case 3:em[i].salary=changesalary();break;case 4:em[i].state=changestate();break;case 5:newem=em[i];changmany();em[i]=newem;break;case 0:mainmenu();default :printf("输入有错误");}}fwrite(&em[i],sizeof(struct employee),1,fp);}fclose(fp);if(l==0){printf("该员工不存在,请查证后再输入!\n");select();}•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•22楼elseprintf("操作完成按任意键返回主菜单\n");getch();}int changeposition(){int newposition;printf("请选择新职位1为董事长2为总经理3为副总经理4为经理5为副经理6为秘书7为技术员8为领班9为普通员工:\n");scanf("%d",&newposition);return(newposition);}int changecult(){int newcult;printf("请选择新的文凭1为专家2为博士3为硕士4为学士5为其他:\n");scanf("%d",&newcult);return(newcult);}int changesalary(){int newsalary;printf("请输入新的工资:\n");scanf("%d",&newsalary);return(newsalary);}int changestate(){int newstate;printf("请选择现在的身体情况1好2为一般3为差:\n");scanf("%d",&newstate);return(newstate);}void changmany(){int k;system("cls");printf("请依次输入该员工的新信息\n");do{printf("请选择职位1.董事长2.总经理3.副总经理4.经理5.副经理6.秘书7.技术员8.领班9.普通员工:\n");//输入职位scanf("%d",&k);if(k>=1&&k<=9){newem.position=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入年龄:");scanf("%d",&newem.age);printf("\n");do{printf("请选择文化程度1为专家2为博士3为硕士4为学士5为其他:\n");//输入文化程度scanf("%d",&k);if(k>=1&&k<=5){newem.cult=k;•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•23楼break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入工资:\n");//输入工资scanf("%d",&newem.salary);printf("\n");do{printf("请你选择身体情况1好2为一般3为差:\n");//身体情况scanf("%d",&k);if(k>=1&&k<=3){newem.state=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入联系电话:");scanf("%ld",&newem.tel);printf("\n");printf("请输入地址:");scanf("%s",newem.adr);printf("\n");}void add()//追加一个职工信息{struct employee emp;FILE *fp;int l,k,j,flag=0,i=0;system("cls");if((fp=fopen("num.txt","r+"))==NULL)exit(0);for(i=0;fread(&em[i],sizeof(struct employee),1,fp)!=0;i++);l=i;fclose(fp);if((fp=fopen("employee.txt","ab+"))==NULL){printf("不能够打开这个文件\n");getch();exit(0);}printf("请你输入新人的内容:\n");srand(time(NULL));do{emp.num=rand()%6000+2000; //自动生成工号for(j=0;num[j];j++){if(num[j]==emp.num)•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•24楼{flag=1;break;}}if(flag!=1){num[l]=emp.num;l++;break;}}while(1);printf("请输入姓名:\n"); //输入姓名scanf("%s",);printf("\n");do{printf("请选择性别以1为男2为女:\n"); //输入性别scanf("%d",&k);if(k>=1&&k<=2){emp.sex=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");do{printf("请选择职位1.董事长2.总经理3.副总经理4.经理5.副经理6.秘书7.技术员8.领班9.普通员工:\n");//输入职位scanf("%d",&k);if(k>=1&&k<=9){emp.position=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入年龄:");scanf("%d",&emp.age);printf("\n");do{printf("请选择文化程度1为专家2为博士3为硕士4为学士5为其他:\n");//输入文化程度•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•25楼scanf("%d",&k);if(k>=1&&k<=5){emp.cult=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入工资:\n");//输入工资scanf("%d",&emp.salary);printf("\n");do{printf("请你选择身体情况1好2为一般3为差:\n");//身体情况scanf("%d",&k);if(k>=1&&k<=3){emp.state=k;break;}elseprintf("您的输入有误,请重新输入!\n");}while(1);printf("\n");printf("请输入联系电话:");scanf("%ld",&emp.tel);printf("\n");printf("请输入地址:");scanf("%s",emp.adr);printf("\n");fwrite(&emp,sizeof(struct employee),1,fp);rewind(fp);fclose(fp);if((fp=fopen("num.txt","w+"))==NULL)exit(0);for(i=0;i<l;i++)fwrite(&num[i],sizeof(int),1,fp);fclose(fp);printf("插入完毕,按任意键返回\n");getch();}void del()//删除一个职工信息{int i=0,j=0,l=0,k,b;char choice;int delnum;FILE *fp;if((fp=fopen("employee.txt","r+"))==NULL){printf("文件为空,不能够打开\n");printf("按任意键返回\n");getch();•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•27楼if(num[i]!=delnum)fwrite(&num[i],sizeof(int),1,fp);}fclose(fp);printf("删除成功,按任意键返回!\n");getch();}void count(){FILE *fp;int i=0;int num=0;//总人数统计int mnum=0,fnum=0;//性别人数统计int zjnum=0,bsnum=0,ssnum=0,xsnum=0,othernum=0;//学位人数统计int dsznum=0,zglnum=0,fzglnum=0,glnum=0,fglnum=0;//职位人数统计int mishunum=0,jsynum=0,lbnum=0,ygnum=0;system("cls");if((fp=fopen("employee.txt","r+"))==NULL){printf("不能够打开这个文件\n");exit(0);}do{fread(&em[i],sizeof(struct employee),1,fp);if(feof(fp))break;num++;if(em[i].sex==1) //性别统计mnum++;if(em[i].sex==2)fnum++;if(em[i].cult==1) //文凭统计zjnum++;if(em[i].cult==2)bsnum++;if(em[i].cult==3)ssnum++;if(em[i].cult==4)xsnum++;if(em[i].cult==5)othernum++;if(em[i].position==1) //职位统计dsznum++;if(em[i].position==2)zglnum++;•2010-7-11 12:11•回复••LUZIF200826•2位粉丝•28楼if(em[i].position==3)fzglnum++;if(em[i].position==4)glnum++;if(em[i].position==5)fglnum++;if(em[i].position==6)mishunum++;。

相关主题