学生成绩管理系统V5.0
某班最多有30人(具体人数由键盘输入)参加期末考试,考试科目为数学(MT)、英语(EN)和物理(PH)。定义结构体类型,用结构体数组作函数参数,编程实现如下菜单驱动的学生成绩管理系统:
1.录入每个学生的学号、姓名和各科考试成绩;
2.计算每门课程的总分和平均分;
3.计算每个学生的总分和平均分;
4.按每个学生的总分由高到低排出名次表;
5.按每个学生的总分由低到高排出名次表;
6.按学号由小到大排出成绩表;
7.按姓名的字典顺序排出成绩表;
8.按学号查询学生排名及其考试成绩;
9.按姓名查询学生排名及其考试成绩;
10.按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,对每门课程分别统计每个类别的人数及所占的百分比;
11.输出每个学生的学号、姓名、各科考试成绩,以及每门课程的总分和平均分。
要求程序运行后先显示如下菜单,并提示用户输入选项,根据用户输入的选项执行相应的操作。
1.Append record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by total score of every student
5.Sort in ascending order by total score of every student
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis for every course
11.List record
0.Exit
Please enter your choice:
实验目的:在掌握基本编程结构、函数的基础上,通过增加任务要求,熟悉结构体类型、结构体数组作函数参数、模块化程序设计方法,体会用结构体类型代替普通数组类型实现数据库管理的优越性。
思考:
1.参考教材上的例题,用动态单向链表代替结构体数组,编程实现;
2.在1的基础上,增加“删除记录”和“插入记录”的功能,体会动态链表与结构体数组的不同点和优缺点。
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
struct student
{
char student_num[13];
char student_name[21];
int math, english, physics;
int total_score;
double average_score;
int rating;
};
//定义学生信息的数组
//定义三门课程的总成绩和平均成绩的数组
//定义学生人数
//定义纪录每门课程五个等级人数的数组
student a[31];
int course_total[3];
double course_average[3];
int n;
int math[5], English[5], physics[5];
//1.录入各位学生的信息
void Append_record()
{
int i;
cin >> n;
for (i = 0; i < n; ++i)
{
scanf_s("%s %s %d %d %d", a[i].student_num, 13, a[i].student_name, 21, &a[i].math, &a[i].english, &a[i].physics);
}
}
//2.计算各科目的总成绩和平均成绩
void Caclulate_course()
{
int i;
for (i = 0; i < 3; ++i)
{
course_total[i] = 0;
course_average[i] = 0;
}
for (i = 0; i < n; ++i)
{
course_total[0] += a[i].math;
course_total[1] += a[i].english;
course_total[2] += a[i].physics;
}
for (i = 0; i < 3; ++i)
course_average[i] = course_total[i] / (double)n;
printf("math total score: %d\n", course_total[0]);
printf("math average score: %.3lf\n", course_average[0]);
printf("English total score: %d\n", course_total[1]);
printf("English average score: %.3lf\n", course_average[1]);
printf("physics total score: %d\n", course_total[2]);
printf("physics average score: %.3lf\n", course_average[2]);
}
//3.计算每名学生的总成绩和平均成绩
void Caculate_student()
{
int i;
for (i = 0; i < n; ++i)
{
a[i].total_score = a[i].math + a[i].english + a[i].physics;
a[i].average_score = a[i]