定义工资单类型 struct salary type I r department[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: /*实发工资*
11 定义工资单类型 struct salary_type { char department[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; /* 实发工资 */ };
定义工资表数组 int emp count struct salary type salary list LmAX EMPloYEE] 12
12 定义工资表数组 int emp_count; struct salary_type salary_list[MAX_EMPLOYEE];
2、结构体类型变量的使用 定义了结构体变量后,就可以引用了。 引用时只能引用结构体变量的成员,而 不能整体引用结构体变量。 引用方法: 结构体类型变量名.成员变量名 以职工工资表为例: salary list[i].name:第i个职工的姓 salary1ist[i]. position:第i个职工 的职务 salary list[i]. salary:第i个职工的基 本工资;
13 2、结构体类型变量的使用 • 定义了结构体变量后,就可以引用了。 引用时只能引用结构体变量的成员,而 不能整体引用结构体变量。 • 引用方法: 结构体类型变量名. 成员变量名 • 以职工工资表为例: salary_list[i].name: 第i个职工的姓 名; salary_list[i].position: 第i个职工 的职务; salary_list[i].salary:第i个职工的基 本工资; salary_list[i].date_of_work.da_year: 第i个
[例6-3打印某职工的工资单 /*程序模块 SALARY.H:定义工资单*/ #include <stdlib.h> #include <dos. h> #define maX employee 100 来一—定义工作岗位类型一*/ #define manager /*经 理米 #define engineer 米 程师* #define employee 3 /*职 员* #define worKer /来工 人米 #d THER
14 [例6-3]打印某职工的工资单 /* 程序模块 SALARY.H: 定义工资单 */ #include <stdlib.h> #include <dos.h> #define MAX_EMPLOYEE 100 /*---- 定义工作岗位类型 -----*/ #define MANAGER 1 /* 经 理 */ #define ENGINEER 2 /* 工 程师 */ #define EMPLOYEE 3 /* 职 员 */ #define WORKER 4 /* 工 人 */ #define OTHER 5 /* 其 他 */
/*定义家庭情况类型*/ struct family type int in double harness /*婚姻状况米 int is colleague /*是否双职工*/ struct date birthdate of singleton;/*子女出生日期* int children in school /*上学子女数* int housing area /*住房面积*/ 15
15 /* 定义家庭情况类型 */ struct family_type { int in_double_harness; /* 婚姻状况 */ int is_colleague; /* 是否双职工 */ struct date birthdate_of_singleton; /* 子女出生日期 */ int children_in_school; /* 上学子女数 */ int housing_area; /* 住房面积 */ };