|
|
@ -161,6 +161,29 @@ j+1, sum[j], aver[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//4 函数功能:按选择法将数组sum的元素值排序
|
|
|
|
//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); // 交换姓名
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 5使数据按升序排序
|
|
|
|
// 5使数据按升序排序
|
|
|
|
int Ascending(float a, float b)
|
|
|
|
int Ascending(float a, float b)
|
|
|
@ -181,7 +204,13 @@ temp = *x;
|
|
|
|
*y = temp;
|
|
|
|
*y = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 8交换两个长整型数据
|
|
|
|
// 8交换两个长整型数据
|
|
|
|
|
|
|
|
void SwapLong(long *x, long *y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
long temp;
|
|
|
|
|
|
|
|
temp = *x;
|
|
|
|
|
|
|
|
*x = *y;
|
|
|
|
|
|
|
|
*y = temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
// 9交换两个字符串
|
|
|
|
// 9交换两个字符串
|
|
|
|
void SwapChar(char x[], char y[])
|
|
|
|
void SwapChar(char x[], char y[])
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -229,7 +258,27 @@ SwapChar(stu[k].name, stu[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 12函数功能:按学号查找学生成绩并显示查找结果
|
|
|
|
// 12函数功能:按学号查找学生成绩并显示查找结果
|
|
|
|
|
|
|
|
void SearchbyNum(STU stu[], int n, int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
long number;
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
printf("Input the number you want to search:");
|
|
|
|
|
|
|
|
scanf("%ld", &number);
|
|
|
|
|
|
|
|
for(i=0;i<n;i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (stu[i].num==number)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\nNot found!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// 13函数功能:按姓名的字典顺序排出成绩表
|
|
|
|
// 13函数功能:按姓名的字典顺序排出成绩表
|
|
|
|
void SearchbyName(STU stu[], int n, int m)
|
|
|
|
void SearchbyName(STU stu[], int n, int m)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -297,7 +346,28 @@ void PrintScore(STU stu[], int n, int m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 16输出n个学生的学号、姓名及m门课程的成绩到文件student.txt中
|
|
|
|
// 16输出n个学生的学号、姓名及m门课程的成绩到文件student.txt中
|
|
|
|
|
|
|
|
void WritetoFile(STU stu[], int n, int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((fp = fopen("student.txt","w")) == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("Failure to open score.txt!\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "%d\t%d\n", n, m); //将学生人数和课程门数写入文件
|
|
|
|
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(fp, "%10ld%10s", stu[i].num, stu[i].name);
|
|
|
|
|
|
|
|
for (j=0; j<m; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(fp, "%10.0f", stu[i].score[j]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "%10.0f%10.0f\n", stu[i].sum, stu[i].aver);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//17从文件中读取学生的学号、姓名及成绩等信息写入到结构体数组stu中
|
|
|
|
//17从文件中读取学生的学号、姓名及成绩等信息写入到结构体数组stu中
|
|
|
|
void ReadfromFile(STU stu[],int *n, int *m)
|
|
|
|
void ReadfromFile(STU stu[],int *n, int *m)
|
|
|
|