|
|
|
@ -107,3 +107,71 @@ int Menu(void)
|
|
|
|
|
scanf("%d", &itemSelected); // 读入用户输入
|
|
|
|
|
return itemSelected;
|
|
|
|
|
}
|
|
|
|
|
//1 函数功能:输入n个学生的m门课成绩
|
|
|
|
|
void ReadScore(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
printf("Input student's ID, name and score:\n");
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
{scanf("%ld%s",&stu[i].num,stu[i].name);
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
|
scanf("%f",&stu[i].score[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//2 函数功能:计算每个学生各门课程的总分和平均分
|
|
|
|
|
void AverSumofEveryStudent(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
|
{
|
|
|
|
|
stu[i].sum = 0;
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
|
{
|
|
|
|
|
stu[i].sum = stu[i].sum + stu[i].score[j];
|
|
|
|
|
}
|
|
|
|
|
stu[i].aver = m>0 ? stu[i].sum / m : -1;
|
|
|
|
|
printf("student %d: sum = %.0f, aver = %.0f\n",
|
|
|
|
|
i+1, stu[i].sum, stu[i].aver);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//3 函数功能:计算每门课程的总分和平均分
|
|
|
|
|
void AverSumofEveryCourse(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
float sum[COURSE_NUM], aver[COURSE_NUM];
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
|
{
|
|
|
|
|
sum[j] = 0;
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
|
{
|
|
|
|
|
sum[j] += stu[i].score[j];
|
|
|
|
|
}
|
|
|
|
|
aver[j]=sum[j]/i;
|
|
|
|
|
printf("student %d: sum = %.0f, aver = %.0f\n",
|
|
|
|
|
j+1, sum[j], aver[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//4 函数功能:按选择法将数组sum的元素值排序
|
|
|
|
|
void SortbyScore(STU stu[],int n,int m,int (*compare)(float a,float b))
|
|
|
|
|
{
|
|
|
|
|
int i, j, k, t;
|
|
|
|
|
for (i=0; i<n-1; i++)
|
|
|
|
|
{
|
|
|
|
|
k = i;
|
|
|
|
|
for (j=i+1; j<n; j++)
|
|
|
|
|
{
|
|
|
|
|
if ((*compare)(stu[j].sum, stu[k].sum)) k = j;
|
|
|
|
|
}
|
|
|
|
|
if (k != i)
|
|
|
|
|
{
|
|
|
|
|
for (t=0; t<m; t++) // 交换m门课程的成绩
|
|
|
|
|
{
|
|
|
|
|
SwapFloat(&stu[k].score[t], &stu[i].score[t]);
|
|
|
|
|
}
|
|
|
|
|
SwapFloat(&stu[k].sum, &stu[i].sum); // 交换总分
|
|
|
|
|
SwapFloat(&stu[k].aver, &stu[i].aver); // 交换平均分
|
|
|
|
|
SwapLong(&stu[k].num, &stu[i].num); // 交换学号
|
|
|
|
|
SwapChar(stu[k].name, stu[i].name); // 交换姓名
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|