#include
#include
#define N 5
typedef struct employee
{
int age;
char name[10];
double salary;
}*PEMP;
void update(PEMP*, int, int, char, float);
void readin(PEMP*);
double total(PEMP*);
double mean(PEMP*);
void update(PEMP company[ ], int id, int age, char name[10], float salary)
{
PEMP emp;
emp=(PEMP) malloc (sizeof(struct employee));
if (emp==NULL)
return;
else company[id]=emp;
company[id]->age=age;
strcpy(company[id]->name,name);
company[id]->salary=salary;
}
void readin(PEMP company[ ])
{
int i,m;
int aage;
char aname[10];
float asalary;
printf("请输入所要职工的人数:");
scanf("%d",&m);
for(i=0;i
printf("请输入职工姓名:");
scanf("%s",&aname);
printf("请输入职工年龄:");
scanf("%d",&aage);
printf("请输入职工工资:");
scanf("%f",&asalary);
update(company,i,aage,aname,asalary);
}
}
double total(PEMP company[ ])
{
int i;
int age1;
int age2;
double sum=0;
printf("输入年龄范围");
scanf("%d%d",&age1,&age2);
if(age1>age2)
{
i=age1;
age1=age2;
age2=i;
}
for(i=0;i
if((company[i]->age)>=age1&&(company[i]->age)<=age2)
{
sum+=(company[i]->salary);
}
}
return(sum);
}
double mean(PEMP company[ ])
{
int i;
int age;
int n=0;
double sum=0;
printf("求某一年龄段以上的职工平均工资.\n");
printf("年龄:");
scanf("%d\n",&age);
for(i=0;i
if((company[i]->age)>age)
sum += (company[i]->salary);
++n;
}
printf("年龄:%d,总和:%f\n", age, sum);
sum=sum/n;
return(sum);
}
void main()
{
PEMP company[N];
readin(company);
printf("姓名\t\t年龄\t\t工资\n");
for(int i=0;i
printf("%s\t\t%d\t\t%.2f\n",company[i]->name,company[i]->age,company[i]->salary);
}
printf("总工资:%f",total(company));
printf("平均工资:%f",mean(company));
}