语言实现职工管理系统_第1页
语言实现职工管理系统_第2页
语言实现职工管理系统_第3页
语言实现职工管理系统_第4页
语言实现职工管理系统_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、简单的职工管理系统主要实现以下功能:(1) 新增一名职工:将新增职工对象按姓名以字典方式职工管理文件中。(2) 删除一名职工:从职工管理文件中删除一名职工对象。(3) 查询:从职工管理文件中查询符合某些条件的职工。(4) 修改:检索某个职工对象,对其某些属性进行修改。(5) 排序:按某种需要对职工对象文件进行排序。要求:职工信息包括姓名、性别、出生年月、工作年月、学历、职务、住址、电话等信息。实现提示:(1) 由键盘输入职工对象,以文件方式保存。程序执行时先将文件读入内存。(2) 对职工对象中的"姓名"按字典顺序进行排序。(3) 对排序后的职工对象进行增、删、查询、修改、排

2、序等操作。源代码:#include<stdio.h>#include<stdlib.h>#include<string.h>#include <locale.h>#define I 100static char tempstr20; /*用于临时存储输入信息的数组*/static struct staff int num; char name20; char sex; long byear;/birth year 出生年月 long iyear;/imploy year 工作年月 char education20; char duty20; ch

3、ar address20; char phone20; struct staff *next;*head=NULL,*thisn,*newn,staI=0,temp; /*temp用于交换的中间量*/void cin(void); /*输入信息*/int identify(int num); /*对职工号是否重复进行验证*/void cout(void); /*输出信息*/void sort(void); /*查询排序*/void del(void); /*删除职工信息*/int record(void); /*将文件中的数据录入结构体数组中*/void iyear(int j); /*按工作

4、年月排序*/void education(int j); /*按学历排序*/void modify(void); /*修改职工信息*/ void descending(void); /*学历降序输出*/ void ascending(void); /*学历升序输出*/void printmsg(int i); /*输出信息*/void seek(void); /查询员工信息 int main(void) int flag=1; while(flag) system("cls"); /*清屏*/ printf(" 欢迎登陆职工信息管理系统!n"); pri

5、ntf(" 【1】 输入职工信息 【2】 输出职工信息n"); printf(" 【3】 信息查询排序 【4】 删除职工信息n"); printf(" 【5】 修改职工信息 【6】 查询职工信息n"); printf("请输入以上数字,选择相应的功能: "); switch (getchar() case '1':cin();break; /*调用输入信息的函数*/ case '2':cout();break; /*调用输出信息的函数*/ case '3':sort(

6、);break; /*调用排序的函数*/ case '4':del();break; /*调用删除职工信息函数*/ case '5':modify();break; /*调用修改职工信息的函数*/ case '6':seek();break; /查询员工信息 default:flag=0;break; /*跳出循环体,结束程序*/ return 0;void cin(void) /*输入信息的函数*/ FILE *fp; int receive; /*接收返回值*/ if(fp=fopen("information.txt",

7、"a+")=NULL) /*为读写打开一个文本文件*/ printf("文件打开错误n"); exit(1); /*关闭所有文件,终止正在执行的程序,待用户检查出错误,修改后再运行*/ newn=(struct staff *)malloc(sizeof(struct staff); if(head=NULL) /*连接链表*/ head=newn; thisn=newn; thisn->next=NULL; else thisn=head; while(thisn->next!=NULL) thisn=thisn->next; thi

8、sn->next=newn; thisn=newn; getchar(); /*接收缓冲区中选择菜单时多余的回车*/ fputc('n',fp); /*每次记录信息前先换行*/ printf("请输入职工号:"); gets(tempstr);thisn->num=atoi(tempstr); /*atoi()将字符串转换成整型数*/ receive=identify(thisn->num); while(receive) printf("请输入职工号:"); gets(tempstr);thisn->num=at

9、oi(tempstr); receive=identify(thisn->num); fputs(tempstr,fp); fputs(" ",fp); /*信息排版的需要*/ printf("请输入姓名:"); gets(thisn->name); fputs(thisn->name,fp); fputs(" ",fp); printf("请输入性别(填F或M):"); thisn->sex=getchar();getchar(); fputc(thisn->sex,fp); fpu

10、ts(" ",fp); printf("请输入出生年月(如199001):"); gets(tempstr);thisn->byear=atoi(tempstr); fputs(tempstr,fp); fputs(" ",fp); printf("请输入工作年月(如199001):"); gets(tempstr);thisn->iyear=atoi(tempstr); fputs(tempstr,fp); fputs(" ",fp); printf("请输入学历(博士、

11、硕士、本科、大专、高中、中专、初中、小学、其他):"); gets(thisn->education); fputs(thisn->education,fp); fputs(" ",fp); printf("请输入职务:"); gets(thisn->duty); fputs(thisn->duty,fp); fputs(" ",fp); printf("请输入地址:"); gets(thisn->address); fputs(thisn->address,fp);

12、fputs(" ",fp); printf("请输入电话号码:"); gets(thisn->phone); fputs(thisn->phone,fp); thisn->next=NULL; fclose(fp); system("cls"); /*清屏*/int identify(int num) /*对职工号是否重复进行验证*/ FILE *fp; int i; if(fp=fopen("information.txt","r")=NULL) printf("文

13、件打开错误"); exit(1); for(i=0;i<I;i+) /*将文件中的信息按行写入结构体数组中 */ fscanf(fp,"%d %s %c %ld %ld %s %s %s %sn",&stai.num,&,&stai.sex,&stai.byear, &stai.iyear,&cation,&stai.duty,&stai.address,&stai.phone); if(stai.num=num) system("cls&qu

14、ot;); printf("账号已存在 【1】重新输入 【2】退出系统n"); printf("请输入以上数字,选择相应的功能: "); switch(getchar() case '1':getchar();return(1); /*输入不成功,返回值作为循环条件*/ case '2':exit(1); /*退出系统*/ if(stai.num=0) /*动态限制循环输出的次数*/ break; fclose(fp); return (0); /*输入成功,返回值作为循环条件*/void cout(void) /*输出信

15、息*/ FILE *fp; int s,i,j; system("cls"); if(fp=fopen("information.txt","r")=NULL) printf("文件打开错误"); exit(1); for(i=0;i<I;i+) /*将文件中的信息按行写入结构体数组中并输出 */ fscanf(fp,"%d %s %c %ld %ld %s %s %s %sn",&stai.num,&,&stai.sex,&stai.by

16、ear, &stai.iyear,&cation,&stai.duty,&stai.address,&stai.phone); if(stai.num=0) /*动态限制循环输出的次数*/ break; s=record(); setlocale (LC_COLLATE, ""); for (j=0;j<s-1;j+) for(i=0;i<s-j-1;i+) if(strcoll(,stai+1.name)>0) temp=stai; stai=stai+1; stai+1=temp

17、; printf("工号 姓名 性别 出生年月 工作年月 学历 职务 地址 电话n");printf("-n"); for(i=0;i<s;i+) printmsg(i); fclose(fp); getchar(); /*接收回车*/ printf("nnnnn回到主界面请按r 退出系统请按其他键n"); switch (getchar() case 'r':getchar();system("cls");break; /*getchar()接收回车*/ default:exit(0); v

18、oid sort(void) /*查询排序*/ int j; getchar(); /*接收回车*/ j=record(); printf(" 【1】 按工作年月排序 【2】按学历排序n"); printf("请输入以上数字,选择相应的功能: "); switch (getchar() case '1':iyear(j);break; case '2':education(j);break; getchar(); /*接收回车*/ getchar(); /*接收回车*/ system("cls"); p

19、rintf(" 【1】 回到主界面 【2】退出系统n"); printf("请输入以上数字,选择相应的功能: "); switch(getchar() case '1':getchar();system("cls");break; default:exit(1); void iyear(int j) /*按工作年月排序*/ int i,k; /*i,k用于循环体中以及用于结构体下标*/ system("cls"); for(k=0;k<j-1;k+) for(i=0;i<=j-k-1;i

20、+) if(stai.iyear<stai+1.iyear) temp=stai; stai=stai+1; stai+1=temp; printf("工号 姓名 性别 出生年月 工作年月 学历 职务 地址 电话n");printf("-n"); for(i=0;i<=j-1;i+)printf("%-5d %-10s %-4c %-4ld %-4ld %-6s %-6s %-20s %-sn",stai.num,,stai.sex,stai.byear, stai.iyear,catio

21、n,stai.duty,stai.address,stai.phone); printf(" 【1】返回上一级 【2】退出系统n"); printf("请输入以上数字,选择相应的功能: "); switch (getchar() case '1':system("cls");break; case '2':exit(1);break; void education(int j) /*按学历排序*/ FILE *fp; int i; if(fp=fopen("information.txt&qu

22、ot;,"r")=NULL) printf("文件打开错误"); exit(1); for(i=0;i<I;i+) /*将文件中的信息按行写入结构体数组中 */ if(stai.num=0) /*动态限制循环输出的次数*/ break; fscanf(fp,"%d %s %c %ld %ld %s %s %s %sn",&stai.num,&,&stai.sex,&stai.byear, &stai.iyear,&cation,&stai.

23、duty,&stai.address,&stai.phone); fclose(fp); getchar(); printf(" 【1】学历降序排列 【2】学历升序排列n"); printf("请输入以上数字,选择相应的功能: "); switch(getchar() case '1':descending();break; case '2':ascending();break; printf("nn按任意键返回上一级");void del(void) /*删除职工信息*/ FILE *

24、fp; int num,i,j,k; /*num用于输入要删除的职工号, i用于循环体以及数组下标,j记录职工人数*/ printf("请输入要删除的职工号:"); scanf("%d",&num); getchar(); /*接收回车*/ system("cls"); if(fp=fopen("information.txt","r")=NULL) printf("文件打开错误"); exit(1); for(i=0;i<I;i+) /*将文件中的信息按行写入

25、结构体数组中并输出 */ fscanf(fp,"%d %s %c %ld %ld %s %s %s %sn",&stai.num,&,&stai.sex,&stai.byear, &stai.iyear,&cation,&stai.duty,&stai.address,&stai.phone); if(stai.num=0) break; if(stai.num=num) j=i; fclose(fp); if(fp=fopen("information.tx

26、t","w")=NULL) /*重新向文件输入所有信息*/ printf("文件打开错误"); exit(1); for(k=j;k<record();k+) stak=stak+1; for(i=0;i<record();i+) sprintf(tempstr,"%d",stai.num); /*将整型数转化成字符串*/ fputs(tempstr,fp); fputs(" ",fp); fputs(,fp); fputs(" ",fp); fputc(

27、stai.sex,fp); fputs(" ",fp); sprintf(tempstr,"%ld",stai.byear); fputs(tempstr,fp); fputs(" ",fp); sprintf(tempstr,"%ld",stai.iyear); fputs(tempstr,fp); fputs(" ",fp); fputs(cation,fp); fputs(" ",fp); fputs(stai.duty,fp); fputs("

28、; ",fp); fputs(stai.address,fp); fputs(" ",fp); fputs(stai.phone,fp); fputc('n',fp); fclose(fp); int record(void) /*将文件中的数据录入结构体数组中*/ FILE *fp; int i,j; /*j用于记录职工的人数*/ system("cls"); if(fp=fopen("information.txt","r")=NULL) printf("文件打开错误&quo

29、t;); exit(1); for(i=0,j=0;i<I;i+,j+) /*将文件中的信息按行写入结构体数组中 */ fscanf(fp,"%d %s %c %ld %ld %s %s %s %sn",&stai.num,&,&stai.sex,&stai.byear, &stai.iyear,&cation,&stai.duty,&stai.address,&stai.phone); if(stai.num=0) /*动态限制循环输出的次数*/ break;

30、fclose(fp); return j;void modify(void) /*修改职工信息*/ FILE *fp; int i,num,j; /*num是要修改的职工号,j用于计算职工人数*/ getchar(); /*接收回车*/ system("cls"); printf("请输入要修改的职工号码: "); scanf("%d",&num); getchar(); if(fp=fopen("information.txt","r")=NULL) printf("文件打开

31、错误"); exit(1); for(i=0,j=0;i<I;i+,j+) /*将文件中的信息按行写入结构体数组中并输出 */ fscanf(fp,"%d %s %c %ld %ld %s %s %s %sn",&stai.num,&,&stai.sex,&stai.byear, &stai.iyear,&cation,&stai.duty,&stai.address,&stai.phone); for(i=0;i<I;i+) if(stai.nu

32、m=num) printf(" 【1】 修改姓名 【2】修改学历n"); printf(" 【3】 修改职务 【4】修改住址n"); printf(" 【5】 修改电话 n"); printf("请输入以上数字,选择相应的功能: "); switch (getchar() case '1':getchar(); printf("请输入新姓名:"); gets();printf("修改成功!按任意键返回主界面"); getchar();brea

33、k; case '2':getchar(); printf("请输入新学历(博士、硕士、本科、大专、高中、中专、初中、小学、其他):"); gets(cation);printf("修改成功!按任意键返回主界面"); getchar();break; case '3':getchar(); printf("请输入新职务:"); gets(stai.duty);printf("修改成功!按任意键返回主界面"); getchar();break; case '4&

34、#39;:getchar(); printf("请输入新地址:"); gets(stai.address);printf("修改成功!按任意键返回主界面"); getchar();break; case '5':getchar(); printf("请输入新电话号码:"); gets(stai.phone);printf("修改成功!按任意键返回主界面"); getchar();break; default:break; fclose(fp); if(fp=fopen("informati

35、on.txt","w")=NULL) /*重新向文件输入所有信息*/ printf("文件打开错误"); exit(1); for(i=0;i<j;i+) sprintf(tempstr,"%d",stai.num); /*将整型数转化成字符串*/ fputs(tempstr,fp); fputs(" ",fp); fputs(,fp); fputs(" ",fp); fputc(stai.sex,fp); fputs(" ",fp); sp

36、rintf(tempstr,"%ld",stai.byear); fputs(tempstr,fp); fputs(" ",fp); sprintf(tempstr,"%ld",stai.iyear); fputs(tempstr,fp); fputs(" ",fp); fputs(cation,fp); fputs(" ",fp); fputs(stai.duty,fp); fputs(" ",fp); fputs(stai.address,fp); fpu

37、ts(" ",fp); fputs(stai.phone,fp); fputc('n',fp); fclose(fp);void descending(void) /*按降序排列每个职工的学历*/ int i; system("cls");printf("工号 姓名 性别 出生年月 工作年月 学历 职务 地址 电话n");printf("-n"); for(i=0;i<I;i+) if(strcmp(cation,"博士")=0) printmsg(i);

38、for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"硕士")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"本科")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"大专")=0) printmsg(i); for(i=

39、0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"高中")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"中专")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"初中")=0) printmsg(i); for(i=0;i<

40、;I;i+) if(stai.num=0) break; if(strcmp(cation,"小学")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"其他")=0) printmsg(i); void ascending(void) /*按学历升序排列*/ int i; system("cls");printf("工号 姓名 性别 出生年月 工作年月 学历 职务 地址 电话n");

41、printf("-n"); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"小学")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"初中")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"中专"

42、)=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"高中")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"大专")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"本科")=0) printmsg(i); for(i=0;i<I;i+) if(stai.num=0) break; if(strcmp(cation,"硕士")=0) printmsg(i); for(i=0;i<I;i+) if(strcmp(cation,&q

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论