You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
System/mty.md

119 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//1 函数功能输入n个学生的m门课成绩
void ReadScore(STU stu[], int n, int m)
//2 函数功能:计算每个学生各门课程的总分和平均分
void AverSumofEveryStudent(STU stu[], int n, int m)
//3 函数功能:计算每门课程的总分和平均分
void AverSumofEveryCourse(STU stu[], int n, int m)
//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使数据按升序排序
int Ascending(float a, float b)
// 6使数据按降序排序
int Descending(float a, float b)
// 7交换两个单精度浮点型数据
void SwapFloat(float *x, float *y)
// 8交换两个长整型数据
void SwapLong(long *x, long *y)
{
long temp;
temp = *x;
*x = *y;
*y = temp;
}
// 交换两个字符串
void SwapChar(char x[], char y[])
{
char temp[MAX_LEN];
strcpy(temp, x);
strcpy(x, y);
strcpy(y, temp);
}
// 9交换两个字符串
void SwapChar(char x[], char y[])
// 10函数功能:按选择法将数组num的元素值按从低到高排序
// 11函数功能:交换法实现字符串按字典顺序排序
void SortbyName(STU stu[], int n, int m)
// 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);
/* ---------- begain ---------- */
/* ----------- end ----------- */
printf("\nNot found!\n");
}
// 13函数功能:按姓名的字典顺序排出成绩表
void SearchbyName(STU stu[], int n, int m)
// 14函数功能:统计各分数段的学生人数及所占的百分比
void StatisticAnalysis(STU stu[], int n, int m)
// 15函数功能: 打印学生成绩
// 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
void ReadfromFile(STU stu[],int *n, int *m)