|
|
|
|
# 学习成绩管理系统
|
|
|
|
|
|
|
|
|
|
## 系统介绍
|
|
|
|
|
本成绩管理系统是为教师提供管理班级成绩的工具,该系统可以实现的对学生的成绩进行增、删、改、查、信息保存和信息导入等基本信息,以及对学生成绩排序和分段的扩展功能,有利于对学生成绩管理。
|
|
|
|
|
|
|
|
|
|
## 设计思想
|
|
|
|
|
利用结构体——定义STU结构体存储学生学号、姓名、各科成绩、总成绩和平均成绩,利用文件来存储,读取数据。
|
|
|
|
|
|
|
|
|
|
## 功能描述
|
|
|
|
|
- 创建学生基本信息,便于之后查询和浏览
|
|
|
|
|
|
|
|
|
|
- 录入各科学习成绩
|
|
|
|
|
|
|
|
|
|
- 计算每个学生各门课程的总分和平均分
|
|
|
|
|
|
|
|
|
|
- 计算每门课程的总分和平均分
|
|
|
|
|
|
|
|
|
|
- 按每个学生的总分由高到低排出名次表
|
|
|
|
|
|
|
|
|
|
- 按每个学生的总分由低到高排出名次表
|
|
|
|
|
|
|
|
|
|
- 按学号由小到大排出成绩表
|
|
|
|
|
|
|
|
|
|
- 按姓名的字母顺序排出成绩表
|
|
|
|
|
|
|
|
|
|
- 按学号查询学生排名及其考试成绩
|
|
|
|
|
|
|
|
|
|
- 按姓名查询学生排名及考试成绩
|
|
|
|
|
|
|
|
|
|
- 按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,对每门课程分别统计每个类别的人数以及所占的百分比
|
|
|
|
|
|
|
|
|
|
- 输出每个学生的学号、姓名、各科考试成绩、以及每门课程的总分和平均分
|
|
|
|
|
|
|
|
|
|
- 将每个学生的记录信息写入文件
|
|
|
|
|
|
|
|
|
|
- 从文件中读出每个学生的记录信息并显示
|
|
|
|
|
|
|
|
|
|
## 功能设计
|
|
|
|
|
|
|
|
|
|
### 基本框架
|
|
|
|
|
|
|
|
|
|
// 头文件的使用
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
// define定义的全局变量
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
#define MAX_LEN 10 //字符串最大长度
|
|
|
|
|
#define STU_NUM 30 //最多的考试人数
|
|
|
|
|
#define COURSE_NUM 6 //最多的考试科目
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
// 结构体的定义
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
typedef struct student{
|
|
|
|
|
long num; //每个学生的学号
|
|
|
|
|
char name[MAX_LEN]; //每个学生的姓名
|
|
|
|
|
float score[COURSE_NUM]; //每个学生COURSE_NUM门功课的成绩
|
|
|
|
|
float sum; //每个学生的总成绩
|
|
|
|
|
float aver; //每个学生的平均成绩
|
|
|
|
|
}STU;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
// 函数声明
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
int Menu(void); //菜单显示、用户输入函数
|
|
|
|
|
void ReadScore(STU stu[],int n,int m); //学生成绩录入函数
|
|
|
|
|
void AverSumofEveryStudent(STU stu[],int n,int m); //求每个学生总分和平均分的函数
|
|
|
|
|
void AverSumofEveryCourse(STU stu[],int n,int m); //求每门课程总分和平均分的函数
|
|
|
|
|
void SortbyScore(STU stu[],int n,int m,int (*compare)(float a,float b)); //选择法将数组 sum 的元素排序的函数
|
|
|
|
|
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[],char y[]); //用于交换两个字符串的函数
|
|
|
|
|
void AsSortbyNum(STU stu[],int n,int m); //选择法将数组 num 的元素值从低到高排序的函数
|
|
|
|
|
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); //打印学生成绩的函数
|
|
|
|
|
void WritetoFile(STU record[],int n,int m); //输出学生信息到文件中的函数
|
|
|
|
|
void ReadfromFile(STU record[],int *n,int *m); //从文件中读取学生信息的函数
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
// 主函数
|
|
|
|
|
```
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
char ch;
|
|
|
|
|
int n = 0,m = 0;
|
|
|
|
|
STU stu[STU_NUM];
|
|
|
|
|
printf("Input student number(n<%d):",STU_NUM);
|
|
|
|
|
scnaf("%d",&n);
|
|
|
|
|
printf("Input course number(m<=%d):",COURSE_NUM);
|
|
|
|
|
scanf("%d",&m);
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
ch = Menu(); //显示菜单,并读取用户输入
|
|
|
|
|
switch(ch)
|
|
|
|
|
{
|
|
|
|
|
case 1:ReadScore(stu,n,m);
|
|
|
|
|
break;
|
|
|
|
|
case 2:AverSumofEveryCourse(stu,n,m);
|
|
|
|
|
break;
|
|
|
|
|
case 3:AverSumofEveryStudent(stu,n,m);
|
|
|
|
|
break;
|
|
|
|
|
case 4:SortbyScore(stu,n,m,Ascending);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
int itemSelected;
|
|
|
|
|
printf("Management for Studets' 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 evry students\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 name\n");
|
|
|
|
|
printf("7.Sort in dictionary order by name\n");
|
|
|
|
|
printf("8.Search by number\n");
|
|
|
|
|
printf("9.Search by name\n");
|
|
|
|
|
printf("10.Statisit 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 itemSeleted;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
// 函数功能:输入 n 个学生的 m 门课成绩
|
|
|
|
|
```
|
|
|
|
|
void ReadScore(STU stu[],int n,int m)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
//函数功能:计算每个学生各门课程的总分和平均分
|
|
|
|
|
```
|
|
|
|
|
void AverSumofEveryStudent(STU stu[],int n,int m)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
//函数功能:计算每门课程的总分和平均分
|
|
|
|
|
```
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|