计算平均分

ZMY_Sortbyscore流程图
pwgf6yju5 2 years ago
commit 94f531ade2

74
file

@ -85,4 +85,76 @@ case 12:WritetoFile(stu, n, m);
default:printf("Input error!");
}
}
return 0;}
return 0;}
// 函数功能:显示菜单并获得用户键盘输入的选项
int Menu(void)
{
int itemSelected;
printf("Management for Students' scores\n");
printf("1.Input record\n");
printf("2.Calculate total and average score of every course\n");
printf("3.Calculate total and average score of every student\n");
printf("4.Sort in descending order by score\n");
printf("5.Sort in ascending order by score\n");
printf("6.Sort in ascending order by number\n");
printf("7.Sort in dictionary order by name\n");
printf("8.Search by number\n");
printf("9.Search by name\n");
printf("10.Statistic analysis\n");
printf("11.List record\n");
printf("12.Write to a file\n");
printf("13.Read from a file\n");
printf("0.Exit\n");
printf("Please Input your choice:");
scanf("%d", &itemSelected); // 读入用户输入
return itemSelected;
}
// 函数功能输入n个学生的m门课成绩
void ReadScore(STU stu[], int n, int m)
{
int i, j;
printf("Input student's ID, name and score:\n");
/* ---------- begain ---------- */
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]);
}
/* ----------- end ----------- */
}
// 函数功能:计算每个学生各门课程的总分和平均分
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);
}
}
// 函数功能:计算每门课程的总分和平均分
void AverSumofEveryCourse(STU stu[], int n, int m)
{
int i, j;
float sum[COURSE_NUM], aver[COURSE_NUM];
/* ---------- begain ---------- */
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]);
}
/* ----------- end ----------- */
}
Loading…
Cancel
Save