1、#includestdio.h /*数据库输入输出函数库*/#includestdlib.h /*标准函数库*/#includestring.h /*字符串函数库*/#includeconio.h /*屏幕操作函数库*/#define HEADER1 -RSDA-n#define HEADER2 |number | name | jbgz | jj | kk | yfgz | sk | n#define HEADER3 |-|-|-|-|-|-|-|n#define FORMAT |%-8s|%-8s |%8.2f|%8.2f|%8.2f|%8.2f|%8.2f| n#define DATA
2、p-num, p-name, p-jbgz, p-jj, p-kk, p-yfgz, p-sk, p-sfgz#define END -n#define N 60int saveflag=0; /*是否需要存盘的标志变量*/*定义与职工有关的数据结构*/typedef struct employee /*标记为employee*/ char num10; /*职工编号*/char name15; /*职工姓名*/float jbgz; /*基本工资*/ float jj; /*奖金*/float kk; /*扣款*/float yfgz; /*应发工资*/float sk; /*税款*/flo
3、at sfgz; /*实发工资*/RSDA;void menu() /*主菜单*/ system(cls); /*调用DOS命令,清屏。与clrscr()功能相同*/;cprintf( THE EMPLOYEE Management System n);cprintf( *Menu*n);cprintf( * 1 input record 2 delete record *n);cprintf( * 3 search record 4 modify record *n);cprintf( * 5 insert record 6 count record *n);cprintf( * 7 sor
4、t record 8 save record *n);cprintf( * 9 sort record 0 quit system *n);cprintf( *Menu*n); /*cprintf()送格式化输出至文本窗口屏幕中*/ void printheader() /*格式化输出表头*/printf(HEADER1); printf(HEADER2);printf(HEADER3);void printdata(RSDA pp) /*格式化输出表中数据*/RSDA*p;p=&pp;printf(FORMAT,DATA);void Disp(RSDA tp,int n) /*显示数组tp中
5、储存的记录,内容为employee结构中定义的内容*/int i;if(n=0) /*表示没有职工工资记录*/printf(n=Not employee record!n);while(getchar()!=n)continue;getchar();return ;printf(nn);printheader(); /*输出表头头部*/i=0;while(iNot find this employee record!n); /*作用:用于定位数组中符合要求的记录,并返回保存该记录的数组元素下标值 参数:findmess保存要查找的具体内容;nameornum保存按什么数组中查找*/int Lo
6、cate (RSDA tp,int n,char findmess,char nameornum)int i=0;if(strcmp(nameornum,num)=0) /*按职工编号查询*/while (in)if(strcmp(tpi.num,findmess)=0) /*若找到findmess值的职工编号*/return i;i+;else if(strcmp(nameornum,name)=0) /*按职工姓名查询*/while (ilens) printf(n exceed the required length! n); /*进行长度校验,超过lens值重新输入*/while (s
7、trlen(n)lens);strcpy(t,n); /*讲输入的字符串复制到自复查un个t中*/ /*输入数值,=树枝*/float numberinput(char *notice)float t=0.00;doprintf(notice); /*显示提示信息*/scanf(%f,&t); /*输入如工资等数值型的值*/if(t=0! n); /*进行数值校验*/while(t0);return t;int Add(RSDA tp,int n)char ch,num10;int i,flag=0;system (cls);Disp (tp,n); /*先打印出已有的职工工资信息*/whil
8、e(1) /*一次可输入多条记录,直至输入职工编号为的记录才结束添加操作*/while(1) /*输入职工编号,保证该编号没有被使用,若输入编号为,则推出添加记录操作*/stringinput(num,10,input number(press 0 return menu):);/*格式化输入编号并校验*/flag=0;if(strcmp(num,0)=0) /*输入为,则推出添加草i做,返回主界面*/return n;i=0;while(iThe number %s is existing,try again?(y/n):,num);scanf(%c,&ch);if(ch=y|ch=Y)co
9、ntinue;elsereturn n;elsebreak;strcpy(tpn.num,num); /*就爱那个字符串num复制到tp.num中*/stringinput(tpn.name,15,Name:); tpn.jbgz=numberinput(jbgz:); /*输入并检验基本工资*/ tpn.jj=numberinput(jiangjin:); /*输入并检验奖金*/ tpn.kk=numberinput(koukuan:); /*输入并检验扣款*/tpn.yfgz=tpn.jbgz+tpn.jj-tpn.kk; /*计算应发工资*/tpn.sk=tpn.yfgz*0.12; /
10、*计算税金,这里取应发工资的%*/tpn.sfgz=tpn.yfgz-tpn.sk; /*计算实发工资*/saveflag=1;n+;return n; /*按职工编号或姓名,查询记录*/ void Qur (RSDA tp,int n) int select; /*1:按编号查,:按姓名查,其他:返回主界面*/ char searchinput20; /*保存用户输入的查询内容*/ int p=0; if(nNo employee record!n); getchar(); return ; system(cls); printf( n=1 Search by number =2 Searc
11、h by namen);printf( please choice1,2:);scanf(%d,&select);if(select=1) /*按编号查询*/stringinput(searchinput,10,input the existing employee number:);p=Locate(tp,n,searchinput,num); /*在数组tp中查找编号为searchinput值的元素,并返回该数组元素的下标值*/if (p!=-1) /*若找到该记录*/printheader();printdata(tpp);printf(END);printf(press any key
12、 to return);getchar();elseNofind();getchar(); else if(select=2) /*按姓名查询*/ stringinput(searchinput,15,input the existing emp;oyee name:); p=Locate(tp,n,searchinput,name); if(p!=-1) printheader(); printdata(tpp); printf(END); printf(press any key to return); getchar(); else Nofind(); getchar(); else W
13、rong(); getchar(); /*删除记录:先找到保存该记录的数组元素的先标值,然后在数组中删除该数组元素*/ int Del(RSDA tp,int n) int sel; char findmess20; int p=0,i=0; if(nNo employee record!n); getchar(); return n; system (cls); Disp(tp,n); printf(n =1 Delect by number =2 Delect by name n); printf( please chioce1,2:); scanf(%d,&sel); if(sel=1)
14、 stringinput(findmess,10,input the existing employee number:); p=Locate(tp,n,findmess,num); getchar(); if(p!=-1) for(i=p+1;idelete success!n); n-; getchar(); saveflag=1; else Nofind(); getchar(); else if(sel=2) /*先按姓名查询到该记录所在的数组元素的下标值*/ stringinput(findmess,15,input the existing employee number:); p
15、=Locate(tp,n,findmess,name); getchar(); if(p!=1) for(i=p+1;idelete success!n); n-; getchar(); saveflag=1; else Nofind(); getchar(); return n; /*修改记录。先按输入的职工编号查询到该记录,然后提示用户修改编号之外的值,编号不能修改*/ void Modify(RSDA tp,int n) char findmess20; int p=0; if(nNo employee record!n); getchar(); return ; system(cls)
16、; printf(modify employee recorder); Disp(tp,n); stringinput(findmess,10,input the existing employee number:); /*输入并检验该编号*/ p=Locate(tp,n,findmess,num); /*查询到该数组,并返回下标值*/ if(p!=-1) /*若p!=-1,表明已经找到该数组元素*/ printf(Number :%s,n,tpp.num); printf(Name:%s,tpp.name); stringinput(tpp.name,15,input new name:);
17、 printf(jbgz:%8.2f,tpp.jbgz); tpp.jbgz=numberinput(jbgz:); printf(jiangjin:%8.2f,tpp.jj); tpp.jj=numberinput(jiangjin:); printf(koukuan:%8.2f,tpp.kk); tpp.kk=numberinput(koukuan:); tpn.yfgz=tpn.jbgz+tpn.jj-tpn.kk; tpn.sk+tpn.yfgz*0.12; tpn.sfgz=tpn.yfgz-tpn.sk; printf(n=modify success!n); getchar();
18、 Disp(tp,n); getchar(); saveflag=1; else Nofind(); getchar(); return; /*插入记录:按职工编号查询到要插入的数组元素的位置,然后在该编号之后插入一个新元组*/ int Insert(RSDA tp,int n) char ch,num10,s10; /*s保存插入点位置之前的编号,num保存输入的新记录的编号*/ RSDA newinfo; int flag=0,i=0,kkk=0; system(cls); Disp (tp,n); while(1) stringinput(s,10,please input insert
19、 location sfter the Number:); flag=0;i=0; while(iThe number %s is not existing,try again?(y/n):,s); scanf(%c,&ch); if(ch=y|ch=Y) continue; else return n; /*以下新记录的输入操作与Add()相同*/ while(1)stringinput (num,10,input new employee number:);i=0;flag=0;while(iSorry,The number %s is not existing,try again?(y/
20、n):,num); scanf(%c,&ch); if(ch=y|ch=Y) continue; else return n; elsebreak;strcpy(newinfo.num,num); /*将字符串num复制到newinfo中*/stringinput(newinfo.name,15,Name);newinfo.jbgz=numberinput(jbgz:); /*输入并检验基本工资*/newinfo.jj=numberinput(jiangjin:); /*输入并检验奖金*/newinfo.kk=numberinput(koukuan:); /*输入并检验扣款*/newinfo.
21、yfgz=newinfo.jbgz+newinfo.jj-newinfo.kk; /*计算*/newinfo.sk=newinfo.yfgz*0.12;newinfo.sfgz=newinfo.yfgz-newinfo.sk;saveflag=1; /*main()有对该全局变量的判断,若为,则进行存盘操作*/for(i=n-1;ikkk;i-) /*从最后一个组织元素开始往下移一个元素位置*/strcpy(tpi+1.num,tpi.num);strcpy(tpi+1.name,tpi.name);tpi+1.jbgz=tpi.jbgz;tpi+1.jj=tpi.jj;tpi+1.kk=tp
22、i.kk;tpi+1.yfgz=tpi.yfgz;tpi+1.sk=tpi.sk;tpi+1.sfgz=tpi.sfgz; strcpy(tpkkk+1.num,newinfo.num); /*在kkk的元素卫视后插入新记录*/ strcpy(tpkkk+1.name,newinfo.name); tpkkk+1.jbgz=newinfo.jbgz; tpkkk+1.jj=newinfo.jj; tpkkk+1.kk=newinfo.kk; tpkkk+1.yfgz=newinfo.yfgz; tpkkk+1.sk=newinfo.sk; tpkkk+1.sfgz=newinfo.sfgz;
23、n+; Disp(tp,n); printf(nn); getchar(); return n; /*统计公司员工的工资在各等级的人数*/ void Tongji(RSDA tp,int n) int count10000=0,count5000=0,count2000=0,count0=0; int i=0; if(nNot employee record!n); getchar(); return; system(cls); Disp(tp,n); i=0; while(i=10000)count10000+;i=i+1;continue; /*实发工资10000*/ if(tpi.sfg
24、z=5000)count5000+;i=i+1;continue; /*5000=2000)count2000+;i=i+1;continue; /*2000=实发工资5000*/ if(tpi.sfgz2000)count0+;i=i+1;continue; /*实发工资= 10000:%d (ren)n,count10000); printf(5000=sfgz10000:%d(ren)n,count5000); printf(2000=sfgz5000:%d(ren)n,count2000); printf(sfgz 2000:%d(ren)n,count0); printf(-n);
25、printf(nnpress any key to return); getchar(); /*利用冒泡排序发实现实发工资从高到低的排序*/ void Sort(RSDA tp,int n)int i=0,j=0,flag=0;RSDA newinfo;if(nNot employee record!n);getchar();return ; system(cls); Disp(tp,n); /*现实排序前的所有记录*/ for(i=0;in;i+) flag=0; for(j=0;jn-1;j+) if(tpj.sfgzsort complete!n ); /*书籍存盘,若用户没有专门进行此操作且对数据有修改,在推出系统时,会提示用户存盘*/ void Save (RSDA tp, int n) FILE* fp; int i=0; fp=fopen(rsda,wb); /*以只写方式打开二进制文件*