1、题目3:职工工资管理系统设计 功能:实现简单的职工工资信息管理,职工工资的基本信息包括编号、姓名、基本工资、奖金、工资总额等 基本要求: 1设计简单的菜单,能够进行系统功能选择。 2实现信息的录入功能。 3在已有信息的基础上添加新的记录。 4删除指定编号的记录。 5修改指定编号的记录 6实现信息的浏览功能 7按编号查询功能 8按工资总额排序功能 #include "stdio.h" #include "stdlib.h" #include "ctype.h" #include "process.h" struct gongzi
2、 /*定义数组*/ { int bianhao; char xingming[10]; int jbgz;/*基本工资*/ int jiangjin; int tatal; struct gongzi *next; }; void print() /*菜单*/ { printf("welcom!\n"); printf("1.创建新信息\n"); printf("2.删除原信息\n");
3、 printf("3.修改原信息\n"); printf("4.按编号查找\n"); printf("5.工资总额排序\n"); } struct gongzi * creat(struct gongzi*head) /*case1创建工资,降序排列*/ { struct gongzi *p1, *p2, *p3; /*p1新增点,p2,p3切点*/ p1 =p2 =p3 =(struct gongzi * )malloc(sizeof(struct gongzi)
4、); printf("创建新信息\n输入编号,姓名,基本工资,奖金\n"); printf("输入编号"); scanf("%d",&p1->bianhao); printf("输入姓名"); scanf("%s",&p1->xingming); printf("输入基本工资"); scanf("%d",&p1->jbgz); printf("输入奖金"); scanf("%d",&p1->jiangjin); p1->tatal =p1->jbgz + p1->jiangjin; p1->next =NULL;
5、 if(head == NULL) { head =p1; } else { p2 =head; while((p2->tatal < p1->tatal) && (p2->next !=NULL)) { p3 =p2; p2 =p2->next; } if(p1->tatal < p2->tatal) { if(head == p1) { head =p1;
6、 } else { p3->next =p1; } p1->next =p2; } else { p2->next =p1; p1->next =NULL; } } return head; } struct gongzi * del(struct gongzi*head) /*case2删除原信息*/ { int bianhao; struct gongzi *p1, *p
7、2; printf("输入要删除的编号"); if(head == NULL) { printf("\nlist is null"); goto end; } p1=head; scanf("%d",&bianhao); while((bianhao != p1->bianhao) && (p1->next != NULL)) { p2 =p1; p1 =p1->next; } if(bianhao ==p1->bianhao) { if(p1 == head) { head =p1->next; }
8、 else { p2->next =p1->next; } printf("%d has been deleted.\n",bianhao); } else { printf("%d not been found!\n",bianhao); } end: return(head); } struct gongzi * change(struct gongzi*head) /*case 3修改原信息*/ { int bianhao;
9、 struct gongzi *p1, *p2; printf("输入要修改的编号"); if(head == NULL) { printf("\nlist is null"); goto end; } p1=head; scanf("%d",&bianhao); while((bianhao != p1->bianhao) && (p1->next != NULL)) { p2 =p1; p1 =p1->next; } if(bianhao ==p1->bianhao) { printf("输入编号"); sca
10、nf("%d",&p1->bianhao); printf("输入姓名"); scanf("%s",&p1->xingming); printf("输入基本工资"); scanf("%d",&p1->jbgz); printf("输入奖金"); scanf("%d",&p1->jiangjin); p1->tatal =p1->jbgz + p1->jiangjin; p1->next =NULL; printf("%d has been change.\n",bianhao); } else { printf("%d n
11、ot been found!\n",bianhao); } end: return(head); } struct gongzi * search(struct gongzi*head) /*case4按编号查找*/ { int bianhao; struct gongzi *p1, *p2; printf("输入要查找的编号"); if(head == NULL) { printf("\nlist is null"); goto end; } p1=head
12、 scanf("%d",&bianhao); while((bianhao != p1->bianhao) && (p1->next != NULL)) { p2 =p1; p1 =p1->next; } if(bianhao ==p1->bianhao) { printf("%5d%10s%5d%5d%5d\n",p1->bianhao, p1->xingming,p1->jbgz, p1->jiangjin, p1->tatal); } else { printf("%d not been found!\n",bianhao);
13、 } end: return(head); } void list(struct gongzi*head) /*case5输出*/ { struct gongzi*p1; p1 =head; printf("编号、姓名、基本工资、奖金、工资总额\n"); if(head == NULL) { printf("\nlist is null\n"); } while(p1 != NULL) { printf(
14、"%5d%10s%5d%5d%5d\n",p1->bianhao, p1->xingming,p1->jbgz, p1->jiangjin, p1->tatal); p1 =p1->next; } } main() { int caidan, ch; struct gongzi*p; struct gongzi*head =NULL; loop: print(); scanf("%d",&caidan); switch(caidan) { case 1: head =creat(head); getch(); break; case 2: head =del(head); getch(); break; case 3: head =change(head); getch(); break; case 4: head =search(head); getch(); break; case 5: list(head); getch(); break; } goto loop; }






