当前位置:文档之家› 完整c语言工资管理系统

完整c语言工资管理系统

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<malloc.h>#include<conio.h>#define LEN sizeof(wor)struct worker{long kahao;/*员工工资卡号*/char name[10];/*员工姓名*/int month;//月份float yfgz;/*应发工资*/float sf;/*水费*/float df;/*电费*/float sj;/*税金*/float sfgz;/*实发工资*/struct worker *next;};typedef struct worker wor;int num;void userId();//用户登录函数char menu(void);//主菜单wor *read(wor *head);//加载函数int save(wor *head);//保存函数void inputMenu(wor *head);//输入菜单void input(wor **head);//输入员工信息void searchMenu(wor *head);//查询菜单int numSearch(wor *pNew);//卡号查询方式函数int nameSearch(wor *pNew);//姓名查询方式函数void search(wor *head);//查询功能void deleteSal(wor *head);//删除员工信息wor *deleteNode(wor *head, long nodeNum);//找到删除节点void printSal(wor *head);//打印员工信息void totalSalMenu(wor *head);//统计工资菜单void totalSal(wor *head);/*统计员工某时间段的实发工资总和*/void DeleteMemory(wor *head);//删除内存void order(wor *head);//排序浏览函数char menu1(void);//排序浏览菜单void modify(wor *head);//修改函数,修改完后保存信息void modifyNode(wor *head);//查找节点并修改信息/*==================================================================== ==========================*/int main()/*主函数main,功能:通过调用各函数,实现员工工资信息管理系统的功能*/ {char ch;wor *head=NULL;system("color f2");printf("\n");printf("\n");printf("\n");printf("\n");printf("\n");printf("#〓§〓〓〓〓〓§〓〓〓〓〓〓§〓〓〓〓〓〓§〓〓〓〓〓〓§〓〓〓〓〓〓§〓#\n");printf("↓↓↓↓↓↓\n");printf("☆★☆☆★☆☆★☆☆★☆☆★☆☆★☆\n");printf("☆欢☆☆迎☆☆进☆☆入☆☆系☆☆统☆\n");printf("☆★☆☆★☆☆★☆☆★☆☆★☆☆★☆\n");printf("↓↓↓↓↓↓\n");printf("※※※※※※\n");printf("※※※※※※\n");getchar();userId();system("cls");while(1){ch=menu();switch(ch)/*用switch语句实现功能选择*/{case '1':head=read(head);inputMenu(head);break;/*调用创建链表函数,添加员工工资信息,并保存到文件夹中*/ case '2':head=read(head);searchMenu(head);break;/*调用信息查询函数,查询员工工资信息*/case '3':head=read(head);deleteSal(head);break;/*调用删除信息函数,删除员工工资信息*/case '4':head=read(head);printSal(head);break;/*调用显示信息资料函数*/case '5':head=read(head);totalSalMenu(head);break;/*统计某时间段员工工资信息*/case '6':head=read(head);order(head);break;/*按照卡号对员工进行排序浏览*/case '7':head=read(head);modify(head);break;//修改员工工资信息case '0':system("cls");printf("\n\n\n\n\n");printf("\t\t#〓§〓〓〓〓〓§〓〓〓〓〓〓§〓〓〓〓〓〓§〓#\n");printf("\t\t↓↓↓↓\n");printf("\t\t☆★☆☆★☆☆★☆☆★☆\n");printf("\t\t☆感☆☆谢☆☆使☆☆用☆\n");printf("\t\t☆★☆☆★☆☆★☆☆★☆\n");printf("\t\t↓↓↓↓\n");printf("\t\t※※※※\n");printf("\t\t※※※※\n");printf("\n\n\n\n\n");printf("\t\t\t\t\t\t\t\t12 软件1班\n");printf("\t\t\t\t\t\t\t\t 蔡文豪\n");printf("\t\t\t\t\t\t\t\t201241404120\n\n\n");getchar();exit(0);/*退出系统,返回主界面*/DeleteMemory(head); /*释放所有已分配的内存*/printf("End of program!");break;default:printf("输入错误,请重试!\n");}save(head);}}/*==================================================================== ==========================*/char menu(void)/*函数menu,功能:主菜单选择界面*/{char ch;printf(" ★☆★工资信息管理系统☆★☆\n");printf("\n");printf("★----------------1 * 输入员工工资信息*-----------------------★\n\n");printf("\t☆----------------2 * 查询员工工资信息*-----------------------☆\n\n");printf("★----------------3 * 删除员工工资信息*-----------------------★\n\n");printf("\t☆----------------4 * 浏览员工工资信息*-----------------------☆\n\n");printf("★----------------5 * 统计实发工资总额*-----------------------★\n\n ");printf("\t☆----------------6 * 工资信息排序处理*-----------------------☆\n");printf("★----------------7 * 修改员工工资信息*-----------------------★\n\n ");printf("\t☆----------------0 * 退出工资管理系统*-----------------------☆\n");/*菜单选择界面*/printf("\n");printf("请输入您的选择:");scanf(" %c",&ch);/*选择操作*/return ch;}/*==================================================================== ==========================*/void userId(){int count=0;char q[5]="1234";char b[5];char c;int i=0;part1:printf("请输入您的密码:");while((c=getch())!=13){putchar('*');b[i]=c;i++;}b[i]='\0';if(strcmp(q,b)!=0){printf("密码错误,请重新输入\n");getchar();count++;if(count>=3){printf("您已经三次输入用户名或密码错误,系统自动退出!\n");exit(0); /*退出系统*/}goto part1;}printf("\n");}/*==================================================================== ==========================*/wor *read(wor *head){FILE *fp;wor *s;wor *p;int n;fp=fopen("D:\\1.txt","rb");//以制度方式打开一个二进制文件if(NULL==fp)//如果打开失败就返回-1;{printf("打开文件失败!\n");head=NULL;return NULL;}head=(wor *)malloc(sizeof(wor));p=head;while(!feof(fp)){//为下个节点分配内存空间s=(wor *)malloc(sizeof(wor));n=fread(s,sizeof(wor),1,fp);//从文件读取数据到节点if(n<1){free(s);p->next=NULL;//最后一个节点为NULLbreak;}num++;p->next=s;//保存下个节点p=p->next;//切换至下个节点p->next=NULL;//最后一个节点为NULL}fclose(fp);return head;}/*==================================================================== ==========================*/int save(wor *head){FILE *fp;wor *p;fp=fopen("D:\\1.txt","wb");if(NULL==fp){printf("打开文件失败!\n");return -1;}p=head->next;do{fwrite(p,LEN,1,fp);//把数据保存到fp指向的文件中p=p->next;}while(p!=NULL);fflush(fp);fclose(fp);return 0;}/*==================================================================== ==========================*/void inputMenu(wor *head){char ch;int i=0;do{input(&head);printf("是否继续添加(Y/N)?\n");printf("请输入您的选择:");scanf(" %c",&ch);i++;}while(ch=='y'||ch=='Y');printf("您添加了%d个员工信息!\n",i);}/*==================================================================== ==========================*/void input(wor **head){wor *s;wor *p;if(*head==NULL)//如果表头为空,先为它分配内存{*head=(wor *)malloc(LEN);p=*head;}else//否则说明有内容,直接切换到尾节点{p=*head;while(p->next)p=p->next;}s=(wor *)malloc(LEN);//为这个节点分配内存printf("请输入员工工资卡号(6位):\n");scanf("%ld",&s->kahao);while(s->kahao<100000||s->kahao>=1000000){printf("输入错误,请重新输入6位员工编号:");scanf("%d",&s->kahao);}printf("请输入员工姓名:");scanf("%s",s->name);printf("请输入您要建立的月份:");scanf("%d",&s->month);printf("请输入此人该月应发工资:");scanf("%f",&s->yfgz);printf("请输入此人该月水费:");scanf("%f",&s->sf);printf("请输入电费:");scanf("%f",&s->df);if(s->yfgz<=800)s->sj=0;else if(s->yfgz>800&&s->yfgz<1400)s->sj=(s->yfgz-800)*0.05;elses->sj=(s->yfgz-1400)*0.10;s->sfgz=s->yfgz-s->sf-s->df-s->sj;p->next=s;//保存这个节点p=p->next;//切换至下一个节点p->next=NULL;printf("已成功添加信息!\n");}/*==================================================================== ==========================*/void searchMenu(wor *head){char ch;do{search(head);printf("是否继续查询(Y/N)?\n");printf("请输入您的选择:");scanf(" %c",&ch);}while(ch=='y'||ch=='Y');}/*==================================================================== ==========================*/void search(wor *head){int a;wor *p=head;printf("\t\t\t*********查询菜单**************\n");printf("\t\t\t* 1 按职工的编号查询*\n");printf("\t\t\t* 2 按职工的姓名查询*\n");printf("\t\t\t* 0 退出*\n");printf("\t\t\t*******************************\n");printf("请按数字键选择:");while(1){scanf("%d",&a);if(a>=0&&a<3);break;printf("输入错误,请重新输入:");}switch(a){case 1:numSearch(p);break;case 2:nameSearch(p);break;case 0:return ;break;}}/*==================================================================== ==========================*/int numSearch(wor *pNew){long n;wor *t;int found=0;printf("请输入您要查询的员工卡号:");scanf("%ld",&n);if(pNew==NULL){printf("没有记录员工工资信息!\n");return -1;}printf("查询结果:\n");while(pNew){t=pNew;if(pNew->kahao==n)//查找与n相同学号的学生信息并打印到屏幕{found=1;printf("卡号姓名月份应发工资水费电费税金实发工资\n");printf("%-ld %-s %-d %-.2f\t%-.2f %-.2f %-.2f %-.2f\n",pNew->kahao,pNew->name,pNew->month,pNew->yfgz,pNew->sf,pNew->df,pNew->sj,pNe w->sfgz);}pNew=pNew->next;}if(found!=1){printf("没有找到符合要求的员工信息!\n");return -1;}getch();system("cls");return 0;}/*==============================================================================================*/int nameSearch(wor *pNew){char name[10];int found;wor *t;printf("请输入您要查询的员工姓名:");scanf("%s",name);if(pNew==NULL){printf("没有记录员工工资信息!\n");return -1;}printf("查询结果:\n");while(pNew){t=pNew;if(strcmp(pNew->name,name)==0)//查找与n相同学号的学生信息并打印到屏幕{found=1;printf("卡号姓名月份应发工资水费电费税金实发工资\n");printf("%-ld %-s %-d %-.2f\t%-.2f %-.2f %-.2f %-.2f\n",pNew->kahao,pNew->name,pNew->month,pNew->yfgz,pNew->sf,pNew->df,pNew->sj,pNe w->sfgz);}pNew=pNew->next;}if(found!=1){printf("没有找到符合要求的员工信息!\n");return -1;}getch();system("cls");return 0;}/*==================================================================== ==========================*/void deleteSal(wor *head)/*删除员工信息*/{int i = 0;long nodeNum;char c;do{printf("请输入您要删除的员工卡号:");scanf(" %ld", &nodeNum);head=deleteNode(head, nodeNum); /*删除卡号为nodeNum的员工信息*/printSal(head); /*显示当前链表中的各节点信息*/printf("是否继续删除员工信息(Y/N)?");scanf(" %c",&c); /*%c前面有一个空格*/i++;}while (c=='Y' || c=='y');printf("%ld new nodes have been deleted!\n", i);save(head);printf("\n");}/*==================================================================== ==========================*/wor *deleteNode(wor *head, long nodeNum){wor *p = head;wor *pr = head;if (head == NULL) /*链表为空,没有节点,无法删除节点*/{printf("No Linked Table!\n");return(head);}/*若没找到节点nodeNum且未到表尾,则继续找*/while (nodeNum != p->kahao && p != NULL){pr = p;p = p->next;}if (nodeNum == p->kahao) /*若找到节点nodeNum,则删除该节点*/{if (p == head) /*若待删除节点为首节点,则让head指向第2个节点*/{head = p->next;}else /*若待删除节点不是首节点,则将前一节点的指针指向当前节点的下一节点*/{pr->next = p->next;}free(p); /*释放为已删除节点分配的内存*/}else /*没有找到待删除节点*/{printf("This Node has not been found!\n");}return head; /*返回删除节点后的链表的头节点指针*/}/*==================================================================== ==========================*/void printSal(wor *head){wor *p1;int j=0;if(head==NULL){printf("没有记录!\n");return ;}p1=head->next;printf("卡号姓名月份应发工资水费电费税金实发工资\n");do{printf("%-ld %s %d %.2f\t%.2f %.2f %.2f %.2f\n",p1->kahao,p1->name,p1->month,p1->yfgz,p1->sf,p1->df,p1->sj,p1->sfgz);j++;if(j%10==0)printf("\n\n");p1=p1->next;}while(p1!=NULL);getch();system("cls");return ;}/*==================================================================== ==========================*/void totalSalMenu(wor *head){char ch;int i=0;do{totalSal(head);printf("是否继续统计(Y/N)?\n");printf("请输入您的选择:");scanf(" %c",&ch);}while(ch=='y'||ch=='Y');}/*==================================================================== ==========================*/void totalSal(wor *head)/*统计员工某时间段的实发工资总和*/{wor *p=head;int start;int end;float sum=0;long number;printf("请输入您要统计工资的员工卡号:");scanf("%ld",&number);if(head==NULL)printf("您输入的卡号不存在!");printf("请输入您要统计工资的月份(0=<n<=m<=12):");scanf("%d %d",&start,&end);while(p!=NULL){if(p->kahao==number){if(p->month>=start&&p->month<=end)sum+=p->sfgz;}p=p->next;}printf("您要统计的月份总实发工资为%.1f\n\n",sum);getch();system("cls");}/*==================================================================== ==========================*/void order(wor *head){char ch;long c;char t[10];float b ;float g;float d ;float e;float f;int i;int j;wor *p1;wor *p2;loop:ch=menu1();switch(ch){case '1': /*按商品编号顺序浏览*/{system("cls");/*清屏*/printf("总有%d个员工的信息:\n",num);printf("卡号姓名月份应发工资水费电费税金实发工资\n");p2=p1=head->next;for(i=1;i<num;i++){for(j=i+1;j<=num;j++){p2=p1;p1=p1->next;if(p2->kahao>p1->kahao)//若后面的卡号小于前面的,则交换信息{c=p2->kahao;p2->kahao=p1->kahao;p1->kahao=c;strcpy(t,p2->name);/*交换前后结点中的卡号值*/strcpy(p2->name,p1->name);strcpy(p1->name,t); /*交换前后结点中的员工姓名,使之与卡号相匹配*/i=p2->month;p2->month=p1->month;p1->month=i;/*交换前后结点中的月份,使之与卡号相匹配*/b=p2->yfgz;p2->yfgz=p1->yfgz;p1->yfgz=b; /*交换前后结点中的应发工资,使之与卡号相匹配*/g=p2->sf;p2->sf=p1->sf;p1->sf=g; /*交换前后结点中的水费,使之与卡号相匹配*/d=p2->df;p2->df=p1->df;p1->df=d; /*交换前后结点中的电费,使之与卡号相匹配*/e=p2->sj;p2->sj=p1->sj;p1->sj=e; /*交换前后结点中的税金,使之与卡号相匹配*/f=p2->sfgz;p2->sfgz=p1->sfgz;p1->sfgz=f; /*交换前后结点中的实发工资,使之与卡号相匹配*/}}p2=head->next;p1=head->next;/*重新使p2,p1指向链表头*/}p1=head->next;do{printf("%-ld %s %d %.2f\t%.2f %.2f %.2f %.2f\n",p1->kahao,p1->name,p1->month,p1->yfgz,p1->sf,p1->df,p1->sj,p1->sfgz);p1=p1->next;}while(p1!=NULL);}getch();system("cls");break;case '2':{system("cls");/*清屏*/printf("总有%d个员工的信息:\n",num);printf("卡号姓名月份应发工资水费电费税金实发工资\n");p2=p1=head->next;for(i=1;i<num;i++){for(j=i+1;j<=num;j++){p2=p1;p1=p1->next;if(p2->sfgz<p1->sfgz)//若前面的实发工资小于后面的,则交换信息{c=p2->kahao;p2->kahao=p1->kahao;p1->kahao=c;/*交换前后结点中的卡号值*/strcpy(t,p2->name);strcpy(p2->name,p1->name);strcpy(p1->name,t); /*交换前后结点中的员工姓名,使之与卡号相匹配*/i=p2->month;p2->month=p1->month;p1->month=i;/*交换前后结点中的月份,使之与卡号相匹配*/b=p2->yfgz;p2->yfgz=p1->yfgz;p1->yfgz=b; /*交换前后结点中的应发工资,使之与卡号相匹配*/g=p2->sf;p2->sf=p1->sf;p1->sf=g; /*交换前后结点中的水费,使之与卡号相匹配*/d=p2->df;p2->df=p1->df;p1->df=d; /*交换前后结点中的电费,使之与卡号相匹配*/e=p2->sj;p2->sj=p1->sj;p1->sj=e; /*交换前后结点中的税金,使之与卡号相匹配*/f=p2->sfgz;p2->sfgz=p1->sfgz;p1->sfgz=f; /*交换前后结点中的实发工资,使之与卡号相匹配*/}}p2=head->next;p1=head->next;/*重新使p2,p1指向链表头*/}p1=head->next;do{printf("%-ld %s %d %.2f\t%.2f %.2f %.2f %.2f\n",p1->kahao,p1->name,p1->month,p1->yfgz,p1->sf,p1->df,p1->sj,p1->sfgz);p1=p1->next;}while(p1!=NULL);}getch();system("cls");break;case '0':{system("cls");return;}default :printf("输入错误!\n");}goto loop;}/*==================================================================== ==========================*/char menu1(void)/*子菜单*/{char ch;printf("\n\n\n\n\n\n");printf("\t $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");printf("\t $$\n");printf("\t $$ 1 * 按卡号升序浏览\n");printf("\t $$\n");printf(" \t $$\t 2 * 按实发工资降序浏览\n");printf("\t $$\t\t\t\t\t\t $$\n");printf(" \t $$\t\t 0 * 退出\t $$\n");printf("\t \t\t\t\t\t\t $$\n");printf("\t\t\t\t\t \t $$\n");printf("\t\t\t\t\t\t\t $$");printf("\n\t\t\t $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");printf("\n\n\n\n\n\n\n");printf("请输入您的选择:");scanf(" %c",&ch);return ch;}/*==================================================================== ==========================*/void modify(wor *head){char c;int i=0;do{modifyNode(head);printf("继续修改请按Y/y!?");printf("其他键视为不修改!\n");printf("你想继续修改记录吗(Y/N)?");scanf(" %c",&c);i++;}while (c=='Y' || c=='y');printf("%d nodes have been modifyied!\n",i);}/*==================================================================== ==========================*/void modifyNode(wor *head){wor *q=head;long d;if(q==NULL){printf("工资表为空请重新输入!!\n");return ;}printf("请输入你想修改的职工的编号:");scanf("%ld",&d);while(q&&q->kahao!=d) //做比较判断//q=q->next; //没找到,指针后移继续查找//if(q==NULL) //指针为空,说明没有找到//{printf("Not found!\n");return ;}else{printf("请输入修改后的职工卡号:");scanf("%ld",&q->kahao);printf("请输入修改后的职工姓名:");scanf("%s",q->name);printf("请输入修改后的月份:");scanf("%d",&q->month);printf("请输入修改后的应发工资:");scanf("%f",&q->yfgz);printf("请输入修改后的水费:");scanf("%f",&q->sf);printf("请输入修改后的电费:");scanf("%f",&q->df);if(q->yfgz<=800)q->sj=0;else if(q->yfgz>800&&q->yfgz<=1400)q->sj=(q->yfgz-800)*0.05;elseq->sj=(q->yfgz-1400)*0.10;q->sfgz=q->yfgz-q->sf-q->df-q->sj;}save(head);// 调用保存函数保存修改记录printf("修改成功!\n");getch();system("cls");}/*==================================================================== ==========================*/void DeleteMemory(wor *head)/*删除*/{wor *p = head, *pr = NULL;while (p != NULL) /*若不是表尾,则释放节点占用的内存*/{pr = p; /*在pr中保存当前节点的指针*/p = p->next; /*让p指向下一个节点*/free(pr); /*释放pr指向的当前节点占用的内存*/ }}。

相关主题