资源描述:
《用c语言编写企业人事管理信息系统》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、企业人事管理信息系统(两种方法)方法一#include"stdio.h"#include"stdlib.h"#include"string.h"structdate{intyear,month,day;};typedefstructmanrecord{intid;charname[20];charsex[10];chardept[20];structdateworktime;structmanrecord*next;}Elemtype;Elemtype*init(){Elemtype*h;h=(Elemtype*)malloc(sizeof(Elemtype));if(h==NULL)
2、{printf("内存空间不足!");returnNULL;}else{h->next=NULL;returnh;}}voidterm(Elemtype*h){Elemtype*p,*q;p=h;while(p!=NULL){q=p;p=p->next;free(q);}}Elemtype*isidExist(Elemtype*h,intid){Elemtype*p;p=h->next;while(p!=NULL)if(p->id==id)returnp;elsep=p->next;returnNULL;}voidinputStaff(Elemtype*h){Elemtype*p;
3、intid;while(1){printf("输入员工编号(小于等于0,则结束输入):");scanf("%d",&id);if(id<=0){printf("数据输入结束。");break;}p=(Elemtype*)malloc(sizeof(Elemtype));if(p==NULL){printf("内存空间不足,输入结束。");break;}p->id=id;printf("输入姓名:");scanf("%s",p->name);printf("输入性别:");scanf("%s",p->sex);printf("输入部门:");scanf("%s",p-
4、>dept);printf("输入员工工作时间:(yyyy-mm-dd):");scanf("%d-%d-%d",&p->worktime.year,&p->worktime.month,&p->worktime.day);p->next=NULL;h->next=p;h=p;}}voidoutputHead(){printf("编号t姓名t性别t部门t工作时间");}voidoutputOneStaff(Elemtype*p){printf("%dt%st%st%st",p->id,p->name,p->sex,p->dept);printf("%d-%d-%
5、d",p->worktime.year,p->worktime.month,p->worktime.day);printf("");}voidoutputStaff(Elemtype*h){Elemtype*p;if(h->next==NULL){printf("链表为空!");return;}outputHead();p=h->next;while(p!=NULL){outputOneStaff(p);p=p->next;}printf("数据输出结束!");}voidsaveStaff(Elemtype*h){FILE*fp;Elemtype*p;if(h->next=
6、=NULL){printf("无数据!");return;}fp=fopen("d:\企业人事管理信息系统\staff.txt","w");if(fp==NULL){printf("文件打开失败!");return;}p=h->next;while(p!=NULL){fprintf(fp,"");fprintf(fp,"%dt%st%st%st",p->id,p->name,p->sex,p->dept);fprintf(fp,"%d-%d-%d",p->worktime.year,p->worktime.month,p->worktime.day);p=p->
7、next;}fclose(fp);printf("已成功存盘!");}voidreadStaff(Elemtype*h){intn;FILE*fp;Elemtype*p;fp=fopen("d:\企业人事管理信息系统\staff.txt","r");if(fp==NULL){printf("文件打开失败!");return;}n=0;while(!feof(fp)){p=(Elemtype*)malloc(sizeof(Elemty