1个回答
展开全部
#include<stdio.h>
const int n = 5;
struct saleperson {
char name[15];
float task;
float sales;
float bonus;
}person[n] = {
{"emp1",50,35,0},{"emp2",50,48,0},
{"emp3",50,18,0},{"emp4",50,42.5,0},
{"emp5",50,60,0}
};
void sort(struct saleperson a[],int n) {
int i,j,k;
struct saleperson t;
for(i = 0; i < n - 1; ++i) {
k = i;
for(j = i + 1; j < n; ++j) {
if(a[k].bonus < a[j].bonus)
k = j;
}
if(k != i) {
t = a[i];
a[i] = a[k];
a[k] = t;
}
}
}
int main() {
int i;
float p;
for(i = 0;i < n; ++i) {
p = 100 * person[i].sales/person[i].task;
if(p < 40.0) person[i].bonus = 0;
else if( p >= 40.0f && p < 80.0f) person[i].bonus = (p - 40.0f) * 0.008f * person[i].task;
else if(p >= 80.0f) person[i].bonus = (p - 80.0f) * 0.01f * person[i].task + 0.40f * 0.008f * person[i].task;
}
for(i = 0; i < n; ++i)
printf("%8s%8.0f%8.1f%8.4f\n",person[i].name,person[i].task,person[i].sales,person[i].bonus);
printf("\n");
sort(person,n);
for(i = 0; i < n; ++i)
printf("%8s%8.0f%8.1f%8.4f\n",person[i].name,person[i].task,person[i].sales,person[i].bonus);
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询