| |
| #include "head.h" |
| |
| void menu() |
| { |
| |
| switch (main_menu()) |
| { |
| case 1: |
| system("cls"); |
| |
| information_menu(); |
| break; |
| case 2: |
| system("cls"); |
| |
| staff_search_menu(); |
| break; |
| case 3: |
| system("cls"); |
| |
| delete_staff_menu(); |
| break; |
| case 4: |
| system("cls"); |
| |
| staff_salary_search(); |
| |
| break; |
| case 5: |
| system("cls"); |
| |
| staff_statistics(); |
| |
| break; |
| case 0: |
| system("cls"); |
| printf("\t\t\t\t正在退出员工工资系统....."); |
| exit(0); |
| break; |
| default: |
| system("cls"); |
| printf("\t\t\t\t请重新输入!"); |
| menu(); |
| break; |
| } |
| } |
| |
| |
| |
| |
| float tax(float salary) |
| { |
| |
| |
| float tax_need; |
| |
| |
| |
| |
| if (salary <= 5000) |
| { |
| tax_need = 0; |
| } |
| else if (salary > 5000 && salary <= 8000) |
| { |
| tax_need = (salary - 5000) * 0.03; |
| } |
| else if (salary > 8000 && salary <= 17000) |
| { |
| |
| |
| tax_need = (8000 - 5000) * 0.03 + (salary - 8000) * 0.1; |
| |
| } |
| else if (salary > 17000 && salary <= 30000) |
| { |
| |
| tax_need = (8000-5000) * 0.03 + (17000 - 8000) * 0.1 + (salary - 17000)*0.2; |
| } |
| else if (salary > 30000 && salary <= 40000) |
| { |
| |
| tax_need = (8000 - 5000) * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.2 |
| + (salary - 30000) * 0.25; |
| } |
| else if (salary > 40000 && salary <= 60000) |
| { |
| |
| tax_need = (8000 - 5000) * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.24 |
| + (40000 - 30000) * 0.25 + (salary - 40000) * 0.3; |
| } |
| else if (salary > 60000 && salary <= 85000) |
| { |
| |
| tax_need = (8000 - 5000) * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.2 |
| + (40000 - 30000) * 0.25 + (60000 - 40000) * 0.3 + (salary - 60000) * 0.35; |
| } |
| else if (salary > 85000) |
| { |
| |
| tax_need = (8000 - 5000) * 0.03 + (17000 - 8000) * 0.1 + (30000 - 17000) * 0.2 |
| + (40000 - 30000) * 0.25 + (60000 - 40000) * 0.3 + (85000 - 60000) * 0.35 |
| + (salary - 85000) * 0.45; |
| } |
| return tax_need; |
| } |
| |
| void InsertList(Node* n) |
| { |
| Node *n_list = (Node*)malloc(sizeof(Node)); |
| n_list = n; |
| n_list->next = NULL; |
| LinkList listIsert = list; |
| |
| if (listIsert->head == NULL) |
| { |
| listIsert->size++; |
| listIsert->head = n_list; |
| return; |
| } |
| Node* N_list = (NodeList)malloc(sizeof(NodeList));; |
| N_list = NULL; |
| N_list = listIsert->head; |
| |
| for (int i = 0; i < listIsert->size; i++) |
| { |
| if (n_list->data.id <= N_list->data.id ) |
| { |
| n_list->next = N_list; |
| |
| listIsert->head = n_list; |
| listIsert->size++; |
| return; |
| } |
| |
| |
| else if (n_list->data.id > N_list->data.id ) |
| { |
| n_list->next = N_list->next; |
| N_list->next = n_list; |
| listIsert->size++; |
| return; |
| |
| } |
| else |
| { |
| N_list = N_list->next; |
| } |
| } |
| |
| |
| } |
| void save_staff(LinkList list_file) |
| { |
| int ch; |
| |
| FILE* fp = NULL; |
| fp = fopen(filename, "w"); |
| if (fp == NULL) |
| { |
| printf("%s\n", strerror(errno)); |
| } |
| |
| sort_id(list); |
| |
| |
| int length = list_file->size; |
| NodeList staff = list_file->head; |
| |
| for(int i=0;i<length;i++) |
| { |
| fprintf(fp, "%d %s %s %d %d %.2f %.2f\n", |
| staff->data.id,staff->data.name,staff->data.department,staff->data.year,staff->data.month,staff->data.salary,staff->data.realsalary ); |
| staff = staff->next; |
| } |
| fclose(fp); |
| fp = NULL; |
| |
| |
| } |
| void open_staff_file() |
| { |
| int ch; |
| FILE* fp = NULL; |
| fp = fopen(filename, "r"); |
| while (!feof(fp)) |
| { |
| struct Node *staff = (Node*)malloc(sizeof(Node));; |
| staff->data.id = NULL; |
| staff->next = NULL; |
| if (fscanf(fp, "%d %s %s %d %d %f %f\n", |
| &staff->data.id, staff->data.name, staff->data.department, |
| &staff->data.year, &staff->data.month, &staff->data.salary, &staff->data.realsalary) != 7) |
| { |
| break; |
| } |
| if (staff->data.id != NULL) |
| { |
| InsertList(staff); |
| } |
| |
| |
| } |
| fclose(fp); |
| fp = NULL; |
| } |
| |
| |
| void menu_frame() |
| { |
| system("cls"); |
| printf("\n"); |
| printf("\t\t\t\t 欢迎进入员工工资管理系统!您可以进行以下操作!\n"); |
| printf("\t\t\t\t********************************************\n"); |
| printf("\t\t\t\t 员工工资管理系统 \n"); |
| printf("\t\t\t\t********************************************\n"); |
| printf("\t\t\t\t\tNo.0—————[0]退 出 | 返回 主 系 统 \n"); |
| } |
| void menu_bottom_frame() |
| { |
| printf("\t\t\t\t\tNo.2*****[其它]返回上一层 \n"); |
| printf("\n\n"); |
| printf("\t\t\t\t====>请输入相对应的信息:"); |
| } |
| int main_menu() |
| { |
| int choose; |
| menu_frame(); |
| printf("\t\t\t\t\tNo.1—————[1]信息录入 \n"); |
| printf("\t\t\t\t\tNo.2—————[2]查看员工信息 \n"); |
| printf("\t\t\t\t\tNo.3—————[3]删除员工信息 \n"); |
| printf("\t\t\t\t\tNo.4—————[4]工资查询 \n"); |
| printf("\t\t\t\t\tNo.5—————[5]统计功能 \n"); |
| menu_bottom_frame(); |
| scanf("%d", &choose); |
| return choose; |
| } |
| |
| void information_menu() |
| { |
| |
| |
| struct Node *staff =(Node*)malloc(sizeof(Node)); ; |
| staff->next = NULL; |
| menu_frame(); |
| printf("\t\t\t\t\tNo.0*****员工信息目录: \n"); |
| printf("\n\n\t\t\t\t====>请输入对应的用户信息(空格分割):\n"); |
| printf("\n\t\t\t\t\tNo.1*****[1]年份:"); |
| scanf("%d",&staff->data.year); |
| printf("\n\t\t\t\t\tNo.2*****[2]月份:"); |
| scanf("%d", &staff->data.month); |
| printf("\n\t\t\t\t\tNo.2*****[3]部门(营销部,开发部,人事部):"); |
| scanf("%s", &staff->data.department); |
| printf("\n\t\t\t\t\tNo.3*****[3]工号(8位):"); |
| scanf("%d", &staff->data.id); |
| printf("\n\t\t\t\t\tNo.2*****[2]姓名:"); |
| scanf("%s", &staff->data.name); |
| printf("\n\t\t\t\t\tNo.2*****[2]应发工资:"); |
| scanf("%f", &staff->data.salary); |
| |
| staff->data.realsalary = staff->data.salary - tax(staff->data.salary); |
| printf("\t\t\t\t\tNo.1*****工号:%d\n \t\t\t\t\tNo.4*****姓名:%s\n\t\t\t\t\tNo.4*****部门: %s\n \t\t\t\t\tNo.4*****年份:%d\n \t\t\t\t\tNo.4*****月份:%d\n \t\t\t\t\tNo.4*****应发工资:%.2f\n \t\t\t\t\tNo.4*****实发工资:%.2f\n", |
| staff->data.id, staff->data.name, staff->data.department, staff->data.year, staff->data.month, staff->data.salary,staff->data.realsalary); |
| int choose; |
| printf("\n\n"); |
| printf("\t\t\t\t\tNo.1*****[1]保存继续添加信息\n"); |
| printf("\t\t\t\t\tNo.2*****[2]删除不保存,重新添加信息\n"); |
| printf("\t\t\t\t\tNo.3*****[3]退出不保存信息\n"); |
| printf("\t\t\t\t\tNo.4*****[其它]退出保存信息\n"); |
| printf("\n\n\t\t\t\t====>请输入对应的用户信息(空格分割):"); |
| scanf("%d", &choose); |
| switch (choose) |
| { |
| case 1: |
| |
| InsertList(staff); |
| save_staff(list); |
| |
| information_menu(); |
| break; |
| case 2: |
| |
| information_menu(); |
| break; |
| case 3: |
| |
| main_menu(); |
| break; |
| default: |
| |
| InsertList( staff); |
| save_staff(list); |
| main_menu(); |
| break; |
| } |
| |
| } |
| |
| void staff_search_menu() |
| { |
| int choose; |
| menu_frame(); |
| printf("\t\t\t\t\tNo.0*****请选择输出方式: \n"); |
| printf("\t\t\t\t\tNo.1*****[1]按年月份升序(同一月工号升序) \n"); |
| printf("\t\t\t\t\tNo.2*****[2]按照部门降序(实发工资升序) \n"); |
| menu_bottom_frame(); |
| scanf("%d", &choose); |
| switch (choose) |
| { |
| case 1: |
| |
| system("cls"); |
| sort_month(list); |
| |
| printf("\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回员工信息输出 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| int i; |
| scanf("%d", &i); |
| switch (i) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_search_menu(); |
| break; |
| default: |
| main_menu(); |
| } |
| case 2: |
| |
| |
| system("cls"); |
| sort_department(list); |
| |
| printf("\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回员工信息输出 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| int m; |
| scanf("%d", &m); |
| switch (m) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_search_menu(); |
| break; |
| default: |
| main_menu(); |
| } |
| |
| default: |
| |
| main_menu(); |
| } |
| } |
| |
| void delete_staff_menu() |
| { |
| int id; |
| menu_frame(); |
| printf("\t\t\t\t\tNo.2*****[0]返回上一层 \n"); |
| printf("\t\t\t\t\tNo.2*****[工号]要删除的员工工号: \n "); |
| printf("\n\n"); |
| menu_bottom_frame(); |
| scanf("%d", &id); |
| switch (id) |
| { |
| case 0: |
| |
| menu(); |
| break; |
| default: |
| |
| printf("删除员工信息"); |
| |
| delete_id(list, id); |
| break; |
| |
| }; |
| |
| |
| } |
| |
| void staff_salary_search() |
| { |
| int choose; |
| int m; |
| menu_frame(); |
| printf("\t\t\t\t\tNo.0*****请选择输出方式: \n"); |
| printf("\t\t\t\t\tNo.1*****[1]根据姓名查询(同名全部输出) \n"); |
| printf("\t\t\t\t\tNo.2*****[2]根据部门查询(实发工资降序) \n"); |
| printf("\t\t\t\t\tNo.2*****[3]根据年月查询(月份部门降序) \n"); |
| menu_bottom_frame(); |
| char name[20]; |
| char department[20]; |
| int year; |
| int month; |
| scanf("%d", &choose); |
| switch (choose) |
| { |
| case 1: |
| |
| printf("\n\n\t\t\t\t====>请输入您要查询的员工姓名:"); |
| scanf("%s", &name); |
| search_name_salary(list,name); |
| printf("\n\n\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回上一级 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| |
| scanf("%d", &m); |
| switch (m) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_salary_search(); |
| break; |
| default: |
| main_menu(); |
| } |
| break; |
| |
| case 2: |
| |
| printf("\n\n\t\t\t\t====>请输入您要查询的部门:"); |
| scanf("%s", &department); |
| dept_staff(list, department); |
| printf("\n\n\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回上一级 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| |
| scanf("%d", &m); |
| switch (m) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_salary_search(); |
| break; |
| default: |
| main_menu(); |
| } |
| break; |
| break; |
| case 3: |
| |
| |
| printf("\n\n\t\t\t\t====>请输入您要查询的年份:"); |
| scanf("%s", &year); |
| printf("\n\t\t\t\t====>请输入您要查询的月份:"); |
| scanf("%s", &month); |
| year_month_salary(list,year,month); |
| printf("\n\n\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回上一级 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| scanf("%d", &m); |
| switch (m) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_salary_search(); |
| break; |
| default: |
| main_menu(); |
| } |
| break; |
| break; |
| default: |
| |
| menu(); |
| |
| break; |
| |
| }; |
| |
| } |
| |
| void staff_statistics() |
| { |
| int choose; |
| int year =0; |
| int month =0; |
| int m; |
| menu_frame(); |
| printf("\t\t\t\t\tNo.0*****请选择输出方式: \n"); |
| printf("\t\t\t\t\tNo.1*****[1]每个员工平均工资(升序) \n"); |
| printf("\t\t\t\t\tNo.2*****[2]年份工资前三名和后三名 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]某年月每个部门纳税总额(按部门升序显示) \n"); |
| menu_bottom_frame(); |
| scanf("%d", &choose); |
| switch (choose) |
| { |
| case 1: |
| |
| |
| every_staff_average_salary(list); |
| printf("\n\n\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回上一级 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| |
| scanf("%d", &m); |
| switch (m) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_statistics(); |
| break; |
| default: |
| main_menu(); |
| } |
| break; |
| case 2: |
| |
| printf("\n\n\t\t\t\t====>请输入您要查询的年份:"); |
| scanf("%d",&year); |
| dept_max_min(list,year); |
| printf("\n\n\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回上一级 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| |
| scanf("%d", &m); |
| switch (m) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_statistics(); |
| break; |
| default: |
| main_menu(); |
| } |
| break; |
| |
| case 3: |
| |
| printf("\n\n\t\t\t\t====>请输入您要查询的年份:"); |
| scanf("%d", &year); |
| printf("\n\t\t\t\t====>请输入您要查询的月份:"); |
| scanf("%d", &month); |
| year_month_tax_all(list,year, month); |
| printf("\n\n\t\t\t\t\tNo.1*****[0]退出系统 \n"); |
| printf("\t\t\t\t\tNo.2*****[1]返回上一级 \n"); |
| printf("\t\t\t\t\tNo.2*****[3]返回主菜单 \n"); |
| printf("\t\t\t\t====>请输入相对应功能的编号(:"); |
| scanf("%d", &m); |
| switch (m) |
| { |
| case 0: |
| exit(0); |
| break; |
| case 1: |
| staff_statistics(); |
| break; |
| default: |
| main_menu(); |
| } |
| break; |
| default: |
| |
| menu(list); |
| break; |
| } |
| } |
| |
| void printList(LinkList list) |
| { |
| Node* p; |
| p = list->head; |
| while (p != NULL) |
| { |
| printf("\t\t\t\t\t%d %s %s %d %d %.2f %.2f\n", p->data.id, p->data.name, p->data.department, p->data.year, p->data.month, p->data.salary, p->data.realsalary); |
| p = p->next; |
| } |
| } |
| |
| void sort_month(LinkList list) |
| { |
| |
| Node* p, * q, * temp; |
| temp = (Node*)malloc(sizeof(Node)); |
| p = list->head; |
| for(int i = list->size;i>0;i--) |
| |
| { |
| q = p->next; |
| |
| while (q != NULL) |
| { |
| |
| |
| |
| |
| if (q->data.year < p->data.year || (q->data.year == p->data.year && q->data.month < p->data.month) || (q->data.year == p->data.year && q->data.month == p->data.month && q->data.id < p->data.id)) |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| temp->data = p->data; |
| p->data = q->data; |
| q->data = temp->data; |
| |
| } |
| else |
| { |
| q = q->next; |
| p = p->next; |
| } |
| |
| } |
| p = list->head; |
| p = p->next; |
| } |
| printList(list); |
| } |
| |
| void sort_department(LinkList list) |
| { |
| |
| Node* p, * q, * temp; |
| p = list->head; |
| temp = (Node*)malloc(sizeof(Node)); |
| for (int i = list->size; i > 0; i--) |
| { |
| q = p->next; |
| |
| while (q != NULL) |
| { |
| if (wcscmp(p->data.department, q->data.department) < 0 |
| || (wcscmp(p->data.department, q->data.department) == 0 && q->data.realsalary < p->data.realsalary)) |
| { |
| |
| temp->data = p->data; |
| p->data = q->data; |
| q->data = temp->data; |
| |
| } |
| else |
| { |
| q = q->next; |
| p = p->next; |
| } |
| |
| |
| } |
| p = list->head; |
| p = p->next; |
| } |
| printList(list); |
| } |
| |
| void delete_id(LinkList list,int id) |
| { |
| |
| Node*d,*pre; |
| |
| |
| d = list->head; |
| pre = list->head; |
| int lenght = list->size; |
| while(d!=NULL) |
| { |
| if (d->data.id == id) |
| { |
| pre->next = d->next; |
| list->size--; |
| } |
| pre = d; |
| d = d->next; |
| } |
| |
| save_staff(list); |
| |
| } |
| |
| void search_name_salary(LinkList list, char name[20]) |
| { |
| |
| Node* s; |
| s = list->head; |
| while (s!=NULL) |
| { |
| if (strcmp(s->data.name, name) == 0) |
| { |
| printf("\n\t\t\t\t====> %s在%d年%d月在%s的实发工资为%.2f",s->data.name,s->data.year,s->data.month,s->data.department,s->data.realsalary); |
| } |
| s = s->next; |
| } |
| } |
| |
| void dept_staff(LinkList list, char department[20]) |
| { |
| Node* d,*s; |
| d = list->head; |
| struct Node* emp = (Node*)malloc(sizeof(Node)); |
| int length = 0; |
| emp->next = NULL; |
| s = emp; |
| while (d != NULL) |
| { |
| if (strcmp(d->data.department, department) == 0) |
| { |
| |
| Node *temp = (Node*)malloc(sizeof(Node)); |
| temp->next = NULL; |
| temp->data = d->data; |
| s->next = temp; |
| s = s->next; |
| length++; |
| } |
| |
| d = d->next; |
| } |
| |
| Node* p, * q, * temp; |
| temp = (Node*)malloc(sizeof(Node)); |
| p = emp->next; |
| printf("%d\n", length); |
| for(int i=length;i>=0;i--) |
| { |
| q = p->next; |
| |
| while (q != NULL) |
| { |
| if (p->data.realsalary < q->data.realsalary) |
| { |
| temp->data = p->data; |
| p->data = q->data; |
| q->data = temp->data; |
| |
| } |
| else |
| { |
| q = q->next; |
| p = p->next; |
| } |
| |
| } |
| p = emp; |
| p = p->next; |
| } |
| |
| emp = emp->next; |
| while (emp != NULL) |
| { |
| printf("\n\t\t\t\t====> %s在%d年%d月在%s的实发工资为%.2f", emp->data.name, emp->data.year, emp->data.month, emp->data.department, emp->data.realsalary); |
| emp = emp->next; |
| } |
| |
| } |
| |
| void year_month_salary(LinkList list, int year, int month) |
| { |
| Node* d, * s; |
| d = list->head; |
| struct Node* emp = (Node*)malloc(sizeof(Node)); |
| int length = 0; |
| emp->next = NULL; |
| s = emp; |
| while (d != NULL) |
| { |
| if (d->data.year==year && d->data.month == month) |
| { |
| |
| Node* temp = (Node*)malloc(sizeof(Node)); |
| temp->next = NULL; |
| temp->data = d->data; |
| s->next = temp; |
| s = s->next; |
| length++; |
| } |
| |
| d = d->next; |
| } |
| |
| Node* p, * q, * temp; |
| temp = (Node*)malloc(sizeof(Node)); |
| p = emp->next; |
| printf("%d\n", length); |
| for (int i = length; i >= 0; i--) |
| { |
| q = p->next; |
| |
| while (q != NULL) |
| { |
| if (strcmp(p->data.department, q->data.department) < 0) |
| { |
| temp->data = p->data; |
| p->data = q->data; |
| q->data = temp->data; |
| |
| } |
| else |
| { |
| q = q->next; |
| p = p->next; |
| } |
| |
| } |
| p = emp; |
| p = p->next; |
| } |
| |
| emp = emp->next; |
| while (emp != NULL) |
| { |
| printf("\n\t\t\t\t====> %s在%d年%d月在%s的实发工资为%.2f", emp->data.name, emp->data.year, emp->data.month, emp->data.department, emp->data.realsalary); |
| emp = emp->next; |
| } |
| |
| } |
| |
| void sort_id(LinkList list) |
| { |
| Node* p, * q, * temp; |
| p = list->head; |
| temp = (Node*)malloc(sizeof(Node)); |
| for (int i = list->size; i >= 0; i--) |
| { |
| q = p->next; |
| |
| while (q != NULL) |
| { |
| if (p->data.id > q->data.id) |
| { |
| |
| temp->data = p->data; |
| p->data = q->data; |
| q->data = temp->data; |
| |
| } |
| else |
| { |
| q = q->next; |
| p = p->next; |
| } |
| |
| |
| } |
| p = list->head; |
| |
| } |
| |
| } |
| |
| void every_staff_average_salary(LinkList list) |
| { |
| struct average* s = (average*)malloc(sizeof(average)); |
| s->next = NULL; |
| Node* d; |
| average* a = (average*)malloc(sizeof(average)); |
| a->next = NULL; |
| d = list->head; |
| a = s; |
| |
| |
| sort_id(list); |
| float total_salary ; |
| int total_month; |
| float average_salary; |
| int p_id; |
| char *name; |
| int id_count; |
| id_count = 0; |
| |
| while ( d != NULL) |
| |
| { |
| total_salary = 0; |
| total_month = 0; |
| p_id = d->data.id; |
| name = d->data.name; |
| while (d->data.id == p_id) |
| { |
| total_month++; |
| total_salary = total_salary + d->data.salary; |
| d = d->next; |
| |
| if (d == NULL) |
| break; |
| } |
| |
| |
| average_salary = total_salary / total_month; |
| struct average* lin_a = (average*)malloc(sizeof(average)); |
| lin_a->next = NULL; |
| lin_a->id = p_id; |
| lin_a->name = name; |
| lin_a->a_salary = average_salary; |
| a->next = lin_a; |
| a = a->next; |
| id_count++; |
| } |
| free(a); |
| |
| average* p, * q, * temp; |
| p = s->next; |
| temp = (average*)malloc(sizeof(average)); |
| |
| for(int i=0;i<id_count;i++) |
| { |
| q = p->next; |
| for (int j = id_count -i; j >0; j--) |
| { |
| |
| if (p->a_salary > q->a_salary) |
| { |
| |
| temp->id = p->id; |
| temp->name = p->name; |
| temp->a_salary = p->a_salary; |
| p->id = q->id; |
| p->name = q->name; |
| p->a_salary = q->a_salary; |
| q->id = temp->id; |
| q->name = temp->name; |
| q->a_salary = temp->a_salary; |
| q = q->next; |
| if (q->id < 0 || q->a_salary < 0) |
| break; |
| p = p->next; |
| } |
| else |
| { |
| |
| q = q->next; |
| if ( q==NULL || q->id < 0 || q->a_salary < 0) |
| break; |
| p = p->next; |
| |
| } |
| } |
| p = s->next; |
| |
| } |
| |
| for (int i = 0; i < id_count; i++) |
| { |
| s = s->next; |
| if (s->id < 0 || s->a_salary < 0) |
| break; |
| printf("\t\t\t\t ID: %d,Name: %s,平均工资: %.2f\n", s->id, s->name, s->a_salary); |
| } |
| } |
| void dept_max_min(LinkList list,int year) |
| { |
| struct salary* s = (salary*)malloc(sizeof(salary)); |
| s->next = NULL; |
| Node* d; |
| salary* a = (salary*)malloc(sizeof(salary)); |
| a->next = NULL; |
| d = list->head; |
| a = s; |
| |
| sort_id(list); |
| float total_salary; |
| int total_month; |
| char *department; |
| int p_id; |
| char *name; |
| int id_count; |
| id_count = 0; |
| |
| |
| |
| |
| while (d != NULL) |
| { |
| |
| total_salary = 0; |
| total_month = 0; |
| p_id = d->data.id; |
| name = d->data.name; |
| department = d->data.department; |
| while (d->data.id == p_id && d->data.year == year) |
| { |
| total_month++; |
| total_salary = total_salary + d->data.salary; |
| d = d->next; |
| |
| if (d == NULL) |
| break; |
| } |
| if (total_month != 0) |
| { |
| |
| struct salary* lin_a = (salary*)malloc(sizeof(salary)); |
| lin_a->next = NULL; |
| lin_a->id = p_id; |
| lin_a->name = name; |
| lin_a->department = department; |
| lin_a->all_salary = total_salary; |
| a->next = lin_a; |
| a = a->next; |
| id_count++; |
| } |
| else |
| { |
| d = d->next; |
| |
| if (d == NULL) |
| break; |
| } |
| } |
| salary* p, * q, * temp; |
| p = s->next; |
| temp = (salary*)malloc(sizeof(salary)); |
| for (int i = list->size; i > 0 && p!=NULL; i--) |
| { |
| q = p->next; |
| |
| while (q != NULL) |
| { |
| if (wcscmp(p->department, q->department) < 0 |
| || (wcscmp(p->department, q->department) == 0 && q->all_salary > p->all_salary)) |
| { |
| temp->id = p->id; |
| temp->name = p->name; |
| temp->department = p->department; |
| temp->all_salary = p->all_salary; |
| |
| p->id = q->id; |
| p->name = q->name; |
| p->department = q->department; |
| p->all_salary = q->all_salary; |
| |
| |
| q->id = temp->id; |
| q->name = temp->name; |
| q->department = temp->department; |
| q->all_salary = temp->all_salary; |
| |
| } |
| else |
| { |
| q = q->next; |
| p = p->next; |
| } |
| |
| |
| } |
| p = s->next; |
| } |
| |
| |
| for (int i = 0; i < id_count; i++) |
| { |
| s = s->next; |
| if (s == NULL || s->id < 0 || s->all_salary < 0) |
| break; |
| printf("\n\t\t\tID: %d,Name: %s,部门: %s , 在%d年内总工资工资: %.2f\n", s->id, s->name, s->department, year, s->all_salary); |
| } |
| |
| } |
| void year_month_tax_all(LinkList list, int year, int month) |
| { |
| |
| char dept[3][20] = { "人事部","营销部","开发部" }; |
| int Tax[3] = { 0,0,0 }; |
| int Person_tax = 0; |
| int Sales_tax = 0; |
| int Develop_tax = 0; |
| |
| for (int j = 0; j < 3; j++) |
| { |
| |
| |
| Node* p; |
| p = list->head; |
| for (int i = list->size; i >= 0; i--) |
| { |
| if (strcmp(p->data.department, dept[j]) == 0) |
| { |
| Tax[j] = Tax[j] + (p->data.salary - p->data.realsalary); |
| } |
| p = p->next; |
| if (p == NULL) |
| { |
| break; |
| } |
| } |
| } |
| for (int n = 0; n < 3; n++) |
| { |
| printf("\t\t\t\t %s 部门的总纳税额为: %d\n", dept[n],Tax[n]); |
| } |
| |
| |
| } |