|
|
@ -39,7 +39,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
### 基本框架
|
|
|
|
### 基本框架
|
|
|
|
|
|
|
|
|
|
|
|
#### 头文件的使用
|
|
|
|
// 头文件的使用
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
#include<stdio.h>
|
|
|
|
#include<stdio.h>
|
|
|
@ -47,7 +47,7 @@
|
|
|
|
#include<string.h>
|
|
|
|
#include<string.h>
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### define定义的全局变量
|
|
|
|
// define定义的全局变量
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
#define MAX_LEN 10 //字符串最大长度
|
|
|
|
#define MAX_LEN 10 //字符串最大长度
|
|
|
@ -55,7 +55,7 @@
|
|
|
|
#define COURSE_NUM 6 //最多的考试科目
|
|
|
|
#define COURSE_NUM 6 //最多的考试科目
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 结构体的定义
|
|
|
|
// 结构体的定义
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
typedef struct student{
|
|
|
|
typedef struct student{
|
|
|
@ -67,7 +67,7 @@ typedef struct student{
|
|
|
|
}STU;
|
|
|
|
}STU;
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 函数声明
|
|
|
|
// 函数声明
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
int Menu(void); //菜单显示、用户输入函数
|
|
|
|
int Menu(void); //菜单显示、用户输入函数
|
|
|
@ -90,7 +90,7 @@ void WritetoFile(STU record[],int n,int m); //输出学生信息到文
|
|
|
|
void ReadfromFile(STU record[],int *n,int *m); //从文件中读取学生信息的函数
|
|
|
|
void ReadfromFile(STU record[],int *n,int *m); //从文件中读取学生信息的函数
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
#### 主函数
|
|
|
|
// 主函数
|
|
|
|
```
|
|
|
|
```
|
|
|
|
int main(void)
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -113,13 +113,182 @@ int main(void)
|
|
|
|
case 3:AverSumofEveryStudent(stu,n,m);
|
|
|
|
case 3:AverSumofEveryStudent(stu,n,m);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 4:SortbyScore(stu,n,m,Ascending);
|
|
|
|
case 4:SortbyScore(stu,n,m,Ascending);
|
|
|
|
printf("\nSort in ascending order by score:\n");
|
|
|
|
printf("\nSort in descending order by score:\n");
|
|
|
|
|
|
|
|
PrintScore(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:SortbyScore(stu,n,m,Ascending);
|
|
|
|
|
|
|
|
printf("\nSort in ascending order by number:\n");
|
|
|
|
|
|
|
|
PrintScore(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:AsSortbyNum(stu,n,m);
|
|
|
|
|
|
|
|
printf("\nSort in ascending order by number:\n");
|
|
|
|
|
|
|
|
PrintScore(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:SortbyName(stu,n,m);
|
|
|
|
|
|
|
|
printf("\nSort in dictionary order by name:\n");
|
|
|
|
|
|
|
|
PrintScore(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:SearchbyNum(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:SearchbyName(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:StatisticAnalysis(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:PrintScore(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:WritetoFile(stu,n,m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 13:ReadfromFile(stu,&n,&m);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:printf("End of program!);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
default:printf("Input error!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 函数功能:显示菜单并获得用户键盘输入的选项
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
int Menu(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 函数功能:输入 n 个学生的 m 门课成绩
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void ReadScore(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:计算每个学生各门课程的总分和平均分
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void AverSumofEveryStudent(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
#### 成绩录入
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
设计思想:成绩录入是对结构体中班级、姓名、学号和五门成绩的录入,同时加上对五门成绩平均成绩的计算。按照基本的录入,只需要scanf函数对数据输入,用printf函数进行汉字的打印即可。然后进行文件保存该组数据,最后判断是否继续录入。
|
|
|
|
//函数功能:计算每门课程的总分和平均分
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void AverSumofEveryCourse(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:按选择法将数组 sum 的元素值排序
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
voidSortbyScore(STU stu[],int n,int m,int(*compare)(float a,float b))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//使数据按升序排序
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
int Ascending(float a,float b)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//使数据按降序排序
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
int Descending(float a,float b)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//交换两个单精度浮点型数据
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void SwapFloat(float *x,float *y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//交换两个长整型数据
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void SwapLong(long *x,long *y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//交换两个字符串
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void SwapChar(char x[],chary[])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:按选择法将数组 num 的元素从低到高排序
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void AsSortbyNum(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:交换法实现字符串按字典顺序排序
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void SortbyName(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:按学号查找学生成绩并显示查找结果
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void SearchbyNum(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:按姓名的字典顺序排出成绩表
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void SearchbyName(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:统计各分数段的学生人数及所占的百分比
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void StatisticAnalysis(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//函数功能:打印学生成绩
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void PrintScore(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//输出 n 个学生的学号、姓名及 m 门课程的成绩到文件 student.txt 中
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void WritetoFile(STU stu[],int n,int m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//从文件中读取学生的学号、姓名及成绩等信息写入到结构体 stu 中
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
void ReadfromFile(STU stu[],int *n,int *m)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|