学生成绩管理系统V2.0
某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,参考前面章节的“学生成绩管理系统V1.0”,用一维数组和函数指针作函数参数编程实现如下菜单驱动的学生成绩管理系统:
(1)录入每个学生的学号和考试成绩;
(2)计算课程的总分和平均分;
(3)按成绩由高到低排出名次表;
(4)按成绩由低到高排出名次表;
(5)按学号由小到大排出成绩表;
(6)按学号查询学生排名及其考试成绩;
(7)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;
(8)输出每个学生的学号、考试成绩。
要求程序运行后显示的菜单如下:
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please enter your choice:
然后,根据用户输入的选项执行相应的操作。**
程序运行结果示例:
Input student number(n<30):
6↙
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
1↙
Input student’s ID and score:
11003001↙
87↙
11003005↙
98↙
11003003↙
75↙
11003002
48
11003004↙
65↙
11003006↙
100↙
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
2↙
sum=473,aver=78.83
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
3↙
Sort in descending order by score:
11003006 100
11003005 98
11003001 87
11003003 75
11003004 65
11003002 48
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
4↙
Sort in ascending order by score:
11003002 48
11003004 65
11003003 75
11003001 87
11003005 98
11003006 100
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
5↙
Sort in ascending order by number:
11003001 87
11003002 48
11003003 75
11003004 65
11003005 98
11003006 100
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
6↙
Input the number you want to search:
11003004↙
11003004 65
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
7↙
<60 1 16.67%
60-69 1 16.67%
70-79 1 16.67%
80-89 1 16.67%
90-99 1 16.67%
100 1 16.67%
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
8↙
11003001 87
11003002 48
11003003 75
11003004 65
11003005 98
11003006 100
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
9↙
Input error!
Management for Students’ scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Search by number
7.Statistic analysis
8.List record
0.Exit
Please Input your choice:
0↙
End of program!
输入格式:
( 1 ) 录入学生的人数:
**输入数据格式为:"%d"
**提示信息为:“Input student number(n<30):\n”
( 2 )录入每个学生的学号和考试成绩:
**输入数据格式为:"%ld%f"
**提示信息为:“Input student’s ID and score:\n”
( 3 )录入待查询学生的学号:
**输入数据格式为:"%ld"
输出格式:
计算课程的总分和平均分:
**输出总分与平均分格式为:“sum=%.0f,aver=%.2f\n”
按成绩由高到低排出名次表:
**输出格式为:"%ld\t%.0f\n"
**提示信息为:“Sort in descending order by score:\n”
按成绩由低到高排出名次表:
**输出格式为:"%ld\t%.0f\n"
**提示信息为:“Sort in ascending order by score:\n”
按学号由小到大排出成绩表:
**输出格式为:"%ld\t%.0f\n"
**提示信息为:“Sort in ascending order by number:\n”
按学号查询学生排名及其考试成绩:
**查询学号输入的提示信息:“Input the number you want to search:\n”
**如果未查到此学号的学生,提示信息为:“Not found!\n”;
**如果查询到该学生,要求输出格式为:c
按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比:
**成绩<60的输出格式为:"<60\t%d\t%.2f%%\n";
**成绩=100的输出格式为:"%d\t%d\t%.2f%%\n";
**其他要求输出百分比格式为:"%d-%d\t%d\t%.2f%%\n"
输出学生成绩格式为:"%ld\t%.0f\n"
用户输入的菜单项超出0-8的选择范围:
***输入提示格式为:“Please Input your choice:\n”
***输出错误提示信息:“Input error!\n”
*/
#include <stdio.h>
//由高到低排
void gao (float* a,int n,long* b);
void xue (long* a,int n,float* b);
//6按学号查询学生排名及其考试成绩;
void chaXun (long a,float* b,long* c,int n);
//(7)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;
void fenLei (float* b,long* c,int n);
int main( )
{
printf("Input student number(n<30):\n");
int n;
scanf("%d",&n);
float grade[n];
long xueHao[n];
float sum = 0;
//打印系统选项(首位)
printf("1.Input record\n2.Caculate total and average score of course\n3.Sort in descending order by score\n4.Sort in ascending order by score\n5.Sort in ascending order by number\n6.Search by number\n7.Statistic analysis\n8.List record\n0.Exit\n");
//进行选择
while (1)
{
printf("Please Input your choice:\n");
int a;//选择
scanf("%d",&a);
switch (a) {
case 1:
//(1)录入每个学生的学号和考试成绩;
for (int i = 0; i < n; i++) {
printf("Input student's ID and score:\n");
scanf("%ld%f",&xueHao[i],&grade[i]);
}
break;
case 2:
//(2)计算课程的总分和平均分;
for (int i = 0; i < n; i++)
sum+=grade[i];
printf("sum=%.0f,aver=%.2f\n",sum,sum*1.0/n);
break;
case 3:
//(3)按成绩由高到低排出名次表;3
printf("Sort in descending order by score:\n");
gao(grade,n,xueHao);
for (int i = 0; i < n; i++)
printf("%ld\t%.0f\n",xueHao[i],grade[i]);
break;
case 4:
//(4)按成绩由低到高排出名次表;
for (int i = 0; i < n; i++) {
printf("%ld\t%.0f\n",xueHao[n-i-1],grade[n-i-1]);
}
break;
case 5:
//(5)按学号由小到大排出成绩表;5
xue(xueHao, n, grade);
for (int i = 0; i < n; i++)
printf("%ld\t%.0f\n",xueHao[i],grade[i]);
break;
case 6:
// (6)按学号查询学生排名及其考试成绩;
printf("Input the number you want to search:\n");
long num;
scanf("%ld",&num);
chaXun(num, grade, xueHao,n);
break;
case 7:
// (7)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;
fenLei (grade,xueHao,n);
break;
case 8:
//(8)输出每个学生的学号、考试成绩。
for (int i = 0; i < n; i++) {
printf("%ld\t%.0f\n",xueHao[i],grade[i]);
}
break;
case 0:
printf("End of program!");
return 0;
break;
default :
printf("Input error!\n");
break;
}
}
return 0;
}
//由高到低排
void gao (float* a,int n,long* b)
{
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (*(a+i) < *(a+j)) {
float t = *(a+i);
*(a+i) = *(a+j);
*(a+j) = t;
long m = *(b+i);
*(b+i) = *(b+j);
*(b+j) = m;
}
}
}
}
void xue (long* a,int n,float* b)
{
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (*(a+i) > *(a+j)) {
long t = *(a+i);
*(a+i) = *(a+j);
*(a+j) = t;
float m = *(b+i);
*(b+i) = *(b+j);
*(b+j) = m;
}
}
}
}
void chaXun (long a,float* b,long* c,int n)
{
int i = 0;
for ( i = 0; i < n; i++) {
if (*(c+i) == a) {
printf("%ld\t%.0f\n",a,*(b+i));
break;
}
}
if (i == n) {
printf("Not found!\n");
}
}
void fenLei (float* b,long* c,int n)
{
int tongJi[5] = {0};
for (int i = 0; i < n; i ++) {
if (*(b+i) < 60) {
tongJi[0]++;
}
else if (*(b+i) < 70)
{
tongJi[1]++;
}
else if (*(b+i) < 80)
{
tongJi[2]++;
}
else if (*(b+i) < 90)
{
tongJi[3]++;
}
else
{
tongJi[4]++;
}
}
//统计每个类别的人数以及所占的百分比;
for (int i = 0; i < 5; i++){
float k = tongJi[i]*1.0/n;
if( i == 0 || i == 4)
printf("<%d\t%d\t%.2f%%\n",60+i*10 ,tongJi[i],k);
else
printf("%d-%d\t%d\t%.2f%%\n",60+i*10-10,60+i*10,tongJi[i],k);
}
}
重要思路:条理清晰的往下写;细致耐心的程序测试