#define SALARY TYPE struct salary type SALARY TYPE char depart[ll] /*工作部门*/ char name [9] /*姓名*/ int position: /*职务*/ struct date date of work;/*参加工作时间*/ struct family type family;/*家庭情况*/ float salary, /*基本工资*/ float subsidy /*岗位津贴*/ float Insurance /*劳保福利* f1 oat child allowance;/*独生子女费* float rent /*房租* float cost of elec;/*电费* float cost of water;/*水费*/ float cost of heating;/*取暖费*/ float cost of education;/保育费*/ float realsum. /*实发工资*/
16 • /* 定义工资单类型 */ #define SALARY_TYPE struct salary_type SALARY_TYPE { char depart[11]; /* 工作部门 */ char name[9]; /* 姓名 */ int position; /* 职务 */ struct date date_of_work; /* 参加工作时间 */ struct family_type family; /* 家庭情况 */ float salary; /* 基本工资 */ float subsidy; /* 岗位津贴 */ float insurance; /* 劳保福利 */ float child_allowance; /* 独生子女费 */ float rent; /* 房租 */ float cost_of_elec; /* 电费 */ float cost_of_water; /* 水费 */ float cost_of_heating; /* 取暖费 */ float cost_of_education;/* 保育费 */ float realsum; /* 实发工资 */ };
函数 print salary 打印某职工的工资单 void print salary (salary type salary) t char position[11] switch(salary. position) i case manageR: strcpy( position,"经理"); break; case EnGineer strcpy( position,"工程师"); break; case employee strcpy( position,N职员”); break case WOrKeR strcpy( position,N工人”); break case other. strcpy( position,"其他"); break; 17
17 函数 print_salary(): void打印某职工的工资单 print_salary(SALARY_TYPE salary) { char position[11]; switch(salary.position) { case MANAGER: strcpy(position, "经理"); break; case ENGINEER: strcpy(position, "工程师"); break; case EMPLOYEE: strcpy(position, “职员”); break; case WORKER: strcpy(position, “工人”); break; case OTHER: strcpy(position, "其他"); break; }
/*打印职工工瓷单* printf( n") printf("部门:%10s姓名:%8s\n", salary. depart, salary. name printf(职务:%10s参加工作时间:%d.%02d.%02dn", position, salary. date of work. da year, salary. date of work. da mon salary. date of work. da day) printf("基本工资:%10.2f岗位津贴:%10.2fn", salary salary, salary. subsidy) printf("劳保福利:%10.2f独生子女费:%10.2fn", salary. insurance, salary. child allowance) printf ("n房租:%10.2f电费:%10.2f\n salary. rent, salary cost of elec printf("水费:%10.2f取暖费:%10.2f\n salary cost of water, salary cost of heating) printf("保育费:%10.2f\n", salary. cost of education); printf("n实发工资:%10.2fn", salary. realsum); printf( -n")
18 /* 打印职工工资单*/ printf("-------------------------------------\n"); printf("部 门: %10s 姓 名: %8s\n", salary.depart, salary.name); printf(“职 务: %10s 参加工作时间:%d.%02d.%02d\n", position, salary.date_of_work.da_year, salary.date_of_work.da_mon, salary.date_of_work.da_day); printf("基本工资: %10.2f 岗位津贴: %10.2f\n", salary.salary, salary.subsidy); printf("劳保福利: %10.2f 独生子女费: %10.2f\n", salary.insurance, salary.child_allowance); printf("\n房 租: %10.2f 电 费: %10.2f\n", salary.rent, salary.cost_of_elec); printf("水 费: %10.2f 取 暖 费: %10.2f\n", salary.cost_of_water, salary.cost_of_heating); printf("保 育 费: %10.2f\n", salary.cost_of_education); printf("\n实发工资: %10.2f\n", salary.realsum); printf("------------------------------------------\n"); }
易/*一测试用主函数一*/ main SALARY TYPE salary list [MAX EMPLOYEE int 1, salary count =0 输入经理张三的工资表 strcpy(salary list [salary count]. name,5k=n) strcpy( salary1ist[ salary count]. depart,"办公室"); salary list [salary count] position= MANAGER salary list[salary count]. date of work. da year=1974 salary list[salary count]. date of work. da mon= 10 salary list [salary count]. date of work. da day =1 salary list [salary count]. salary =3500.0 salary list [salary count]. subsidy 2000.0; salary list [salary count].insurance =200.0 salary list[salary count] child allowance=300.0 salary list[salary count].rent =450.0; salary list[salary count. cost of elec 200.0; salary list [salary count]. cost of water=100.0 salary list[salary count]. cost of heating=454.0 salary list[salary count]. cost of education=780 salary list [salary count]. realsum 3458.0 salary count++
19 /*---- 测试用主函数 ----*/ main() { SALARY_TYPE salary_list[MAX_EMPLOYEE]; int i, salary_count = 0; /*---- 输入经理张三的工资表 ------------*/ strcpy(salary_list[salary_count].name, "张三"); strcpy(salary_list[salary_count].depart, "办公室"); salary_list[salary_count].position = MANAGER; salary_list[salary_count].date_of_work.da_year = 1974; salary_list[salary_count].date_of_work.da_mon = 10; salary_list[salary_count].date_of_work.da_day = 1; salary_list[salary_count].salary = 3500.0; salary_list[salary_count].subsidy = 2000.0; salary_list[salary_count].insurance = 200.0; salary_list[salary_count].child_allowance = 300.0; salary_list[salary_count].rent = 450.0; salary_list[salary_count].cost_of_elec = 200.0; salary_list[salary_count].cost_of_water = 100.0; salary_list[salary_count].cost_of_heating = 454.0; salary_list[salary_count].cost_of_education = 78.0; salary_list[salary_count].realsum = 3458.0; salary_count++; }
strcpy (salary list [salary count]. name,"2py") strcpy(salary list [salary count]. depart,4E AJ salary list[salary count] position WORKER salary list[salary count]. date of work. da year =1990 salary list [salary count]. date of work. da mon=7 salary listLsalary count]. date of work. da day=16 salary list[salary count]. salary 500.0 salary list [salary count]. subsidy 100.0 salary list[salary count]. insurance =100.0 salary list [salary count]. child allowance=0.0 salary list [salary count].rent 100.0 salary list[salary count]. cost of elec 100.0 salary list [salary count]. cost of water 100.0 salary list[salary count]. cost of heating=100.0 salary list[salary count]. cost of education =0.0 salary list[salary count. realsum 300.0; salary count++;
20 /* 输入工人李四的工资表 */ strcpy(salary_list[salary_count].name, "李四"); strcpy(salary_list[salary_count].depart, "车间"); salary_list[salary_count].position = WORKER; salary_list[salary_count].date_of_work.da_year = 1990; salary_list[salary_count].date_of_work.da_mon = 7; salary_list[salary_count].date_of_work.da_day = 16; salary_list[salary_count].salary = 500.0; salary_list[salary_count].subsidy = 100.0; salary_list[salary_count].insurance = 100.0; salary_list[salary_count].child_allowance = 0.0; salary_list[salary_count].rent = 100.0; salary_list[salary_count].cost_of_elec = 100.0; salary_list[salary_count].cost_of_water = 100.0; salary_list[salary_count].cost_of_heating = 100.0; salary_list[salary_count].cost_of_education = 0.0; salary_list[salary_count].realsum = 300.0; salary_count++;