|
|
|
@ -121,16 +121,13 @@ 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 ----------- */
|
|
|
|
|
}
|
|
|
|
|
//2
|
|
|
|
|
//2 函数功能:计算每个学生各门课程的总分和平均分
|
|
|
|
|
void AverSumofEveryStudent(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
@ -146,17 +143,24 @@ void AverSumofEveryStudent(STU stu[], int n, int m)
|
|
|
|
|
i+1, stu[i].sum, stu[i].aver);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//3 函数功能:计算每门课程的总分和平均分
|
|
|
|
|
|
|
|
|
|
//4 函数功能:按选择法将数组sum的元素值排序
|
|
|
|
|
|
|
|
|
|
// 5使数据按升序排序
|
|
|
|
|
int Ascending(float a, float b)
|
|
|
|
|
{
|
|
|
|
|
return a < b; // 这样比较决定了按升序排序,如果a<b,则交换
|
|
|
|
|
}
|
|
|
|
|
//6
|
|
|
|
|
// 6使数据按降序排序
|
|
|
|
|
int Descending(float a, float b)
|
|
|
|
|
{
|
|
|
|
|
return a > b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 7交换两个单精度浮点型数据
|
|
|
|
|
|
|
|
|
|
// 8交换两个长整型数据
|
|
|
|
|
|
|
|
|
|
// 9交换两个字符串
|
|
|
|
|
void SwapChar(char x[], char y[])
|
|
|
|
|
{
|
|
|
|
@ -165,7 +169,9 @@ strcpy(temp, x);
|
|
|
|
|
strcpy(x, y);
|
|
|
|
|
strcpy(y, temp);
|
|
|
|
|
}
|
|
|
|
|
//10
|
|
|
|
|
// 10函数功能:按选择法将数组num的元素值按从低到高排序
|
|
|
|
|
|
|
|
|
|
// 11函数功能:交换法实现字符串按字典顺序排序
|
|
|
|
|
void AsSortbyNum(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j, k, t;
|
|
|
|
@ -189,11 +195,18 @@ SwapChar(stu[k].name, stu[i].name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 15函数功能: 打印学生成绩
|
|
|
|
|
void PrintScore(STU stu[], int n, int m)
|
|
|
|
|
// 12函数功能:按学号查找学生成绩并显示查找结果
|
|
|
|
|
|
|
|
|
|
// 13函数功能:按姓名的字典顺序排出成绩表
|
|
|
|
|
void SearchbyName(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
char x[MAX_LEN];
|
|
|
|
|
int i, j;
|
|
|
|
|
printf("Input the name you want to search:");
|
|
|
|
|
scanf("%s", x);
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(stu[i].name, x) == 0)
|
|
|
|
|
{
|
|
|
|
|
printf("%ld\t%s\t", stu[i].num, stu[i].name);
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
@ -201,9 +214,13 @@ void PrintScore(STU stu[], int n, int m)
|
|
|
|
|
printf("%.0f\t", stu[i].score[j]);
|
|
|
|
|
}
|
|
|
|
|
printf("%.0f\t%.0f\n", stu[i].sum, stu[i].aver);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("\nNot found!\n");
|
|
|
|
|
}
|
|
|
|
|
//16
|
|
|
|
|
|
|
|
|
|
// 14函数功能:统计各分数段的学生人数及所占的百分比
|
|
|
|
|
void StatisticAnalysis(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j, t[6];
|
|
|
|
@ -230,6 +247,25 @@ void StatisticAnalysis(STU stu[], int n, int m)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 15函数功能: 打印学生成绩
|
|
|
|
|
void PrintScore(STU stu[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
|
{
|
|
|
|
|
printf("%ld\t%s\t", stu[i].num, stu[i].name);
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
|
{
|
|
|
|
|
printf("%.0f\t", stu[i].score[j]);
|
|
|
|
|
}
|
|
|
|
|
printf("%.0f\t%.0f\n", stu[i].sum, stu[i].aver);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 16输出n个学生的学号、姓名及m门课程的成绩到文件student.txt中
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//17从文件中读取学生的学号、姓名及成绩等信息写入到结构体数组stu中
|
|
|
|
|
void ReadfromFile(STU stu[],int *n, int *m)
|
|
|
|
|
{
|
|
|
|
|