职工信息管理系统源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1#includestdio.h#includestring.h#includestdlib.h#includeconio.hstructDate/*日期*/{intyear;intmonth;intday;};structInfo{charnum[15];/*职工号*/charname[15];/*姓名*/charsex[10];/*性别*/structDatebirthday;/*出生年月*/chareducation[10];/*学历*/charduty[15];/*职务*/doublewage;/*工资*/charaddr[30];/*地址*/charphone[15];/*电话*/};/*************************菜单选择函数******************************/charmenu(){charn;/*n记录选择的菜单*/intsystem(constchar*string);/*清屏*/system(cls);/*清屏*/puts(\t\t欢迎使用职工信息管理系统);puts(\t\t*********************MENU*******************\n);puts(\t\t\t\t1.职工信息录入功能\n);puts(\t\t\t\t2.职工信息浏览功能\n);puts(\t\t\t\t3.职工信息查询功能\n);puts(\t\t\t\t4.职工信息修改功能\n);puts(\t\t\t\t5.职工信息删除功能\n);puts(\t\t\t\t6.退出\n);puts(\t\t********************************************\n);printf(选择你要使用的功能(1-6):[]\b\b);while(1){n=getchar();getchar();if(n'1'||n'6')printf(输入错误,请重新选择你要使用的功能(1-6):[]\b\b);2elsebreak;}returnn;}/****************************信息输入函数****************************/voidappend(){structInfoinfo;FILE*fp;charch;chartemp[10];if((fp=fopen(inform.txt,ab))==NULL){printf(\t文件打开错误!);getch();exit(1);}do{printf(\t号码:);gets(info.num);printf(\t姓名:);gets(info.name);printf(\t性别:);gets(info.sex);printf(\t出生日期(yyyy/mm/dd):);scanf(%d/%d/%d,&info.birthday.year,&info.birthday.month,&info.birthday.day);getchar();printf(\t学历:);gets(info.education);printf(\t职务:);gets(info.duty);printf(\t工资:);gets(temp);info.wage=atof(temp);printf(\t地址:);gets(info.addr);printf(\t电话:);gets(info.phone);fwrite(&info,sizeof(info),1,fp);printf(\t还有更多的吗?(Y/N):[]\b\b);ch=getchar();getchar();}while(ch=='Y'||ch=='y');fclose(fp);}voidprint1(){printf(%-10s%-10s%-10s%-12s%-10s%-10s%-15s%-30s%-15s%\n,号码,姓名,性别,出生日期,学历,职务,工资,地址,电话);}voidprint2(structInfoinfo){;3printf(%-10s%-10s%-10s,info.num,info.name,info.sex);printf(%-4d/%-2d/%-4d,info.birthday.year,info.birthday.month,info.birthday.day);printf(%-10s%-10s%-15.2lf,info.education,info.duty,info.wage);printf(%-30s%-15s\n,info.addr,info.phone);}/***********************职工信息显示函数**************************/voiddisplay(){structInfoinfo;FILE*fp;inttotal=0;if((fp=fopen(inform.txt,rb))==NULL){printf(\t文件打开错误!);getch();exit(1);}while(fread(&info,sizeof(info),1,fp)==1){total++;if(total==1)print1();print2(info);if((total!=0)&&(total%10==0)){printf(\n\n\t按任意键继续。。。。。。);getch();puts(\n\n);print1();}}fclose(fp);printf(\n\n\t这儿一共有%d个记录!\n\n\t按任意键返主菜单。。。。。。。,total);getch();}/***************************信息查询函数*****************************/voidsearch(){structInfoinfo;FILE*fp;intflag;/*flag为1按编号查询,flag为2按姓名查询*/inttotal=0;/*记录符合条件的记录的个数*/charch[10];charf;if((fp=fopen(inform.txt,rb))==NULL)4{printf(\t文件打开错误!);getch();exit(1);}do{rewind(fp);printf(\n\n使用(1:号码2:姓名)查找:[]\b\b);while(1){scanf(%d,&flag);getchar();if(flag1||flag2)printf(输入错误,请重新输入(1:号码2:姓名):[]\b\b);elsebreak;}if(flag==1)/*按编号进行查询*/{printf(请输入你要查找的号码:);gets(ch);total=0;/*符合条件的记录数*/while(fread(&info,sizeof(info),1,fp)==1)if(strcmp(ch,info.num)==0){total++;if(total==1)print1();print2(info);}}else/*按姓名进行查询*/{printf(请输入你要查找的姓名:);gets(ch);total=0;/*符合条件的记录数*/while(fread(&info,sizeof(info),1,fp)==1)if(strcmp(ch,info.name)==0){total++;if(total==1)print1();print2(info);}}printf(\n\n\t共有%d项符合条件!\n,total);5printf(继续查找?(Y/N):[]\b\b);f=getchar();getchar();}while(f=='Y'||f=='y');fclose(fp);}/*************************信息修改函数************************/voidmodify(){structInfoinfo;FILE*fp1,*fp2;intflag;charch[10];charf;chartemp[10];do{if((fp1=fopen(inform.txt,rb))==NULL){printf(\t文件打开错误!);getch();exit(1);}if((fp2=fopen(temp.txt,wb))==NULL){printf(\t文件创建失败!);getch();exit(1);}printf(请输入你要修改的号码:);gets(ch);flag=0;while(fread(&info,sizeof(info),1,fp1)==1){if(strcmp(ch,info.num)==0){print1();print2(info);printf(\n\n请输入新的信息:\n);printf(\t号码:);gets(info.num);printf(\t姓名:);gets(info.name);printf(\t性别:);gets(info.sex);printf(\t出生日期(yyyy/mm/dd):);scanf(%d/%d/%d,&info.birthday.year,&info.birthday.month,&info.birthday.6day);getchar();printf(\t学历:);gets(info.education);printf(\t职务:);gets(info.duty);printf(\t工资:);gets(temp);info.wage=atof(temp);printf(\t地址:);gets(info.addr);printf(\t电话:);gets(info.phone);flag=1;}fwrite(&info,sizeof(info),1,fp2);}fclose(fp1);fclose(fp2);if(flag==1){printf(修改成功!\n);remove(inform.txt);rename(temp.txt,inform.txt);}elseprintf(没有找到记录!\n);printf(继续修改?(Y/N):[]\b\b);f=getchar();getchar();}while(f=='Y'||f=='y');}/*********************信息删除函数**************************/voiddelete(){structInfoinfo;FILE*fp1,*fp2;intflag;charch[10];charf;chartemp[10];do{if((fp1=fopen(inform.txt,rb))==NULL){printf(\t文件打开错误!);getch();exit(1);}if((fp2=fopen(temp.txt,wb))==NULL)7{printf(\t文件创建失败!);getch();exit(1);}printf(请输入你要删除的号码:);gets(ch);flag=0;while(fread(&info,sizeof(info),1,fp1)==1){if(strcmp(ch,info.num)==0){print1();print2(info);flag=1;continue;}elsefwrite(&info,sizeof(info),1,fp2);}fclose(fp1);fclose(fp2);if(flag==1){printf(删除成功!\n);remove(inform.txt);rename(temp.txt,inform.txt);}elseprintf(没找到要删除的号码!\n);printf(继续删除?(Y/N):[]\b\b);f=getchar();getchar();}while(f=='Y'||f=='y');}caozuo(){while(1)switch(menu()){case'1':append();break;case'2'

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功