某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,编程实现如下学生成绩管理:
(1)录入每个学生的学号和考试成绩;
(2)计算课程的总分和平均分;
(3)按成绩由高到低排出名次表;
(4)按学号由小到大排出成绩表;
(5)按学号查询学生排名及其考试成绩;
(6)按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,统计每个类别的人数以及所占的百分比;
(7)输出每个学生的学号、考试成绩,以及课程总分和平均分。
输入格式:
( 1 ) 录入学生的人数:
要求输入数据格式为:"%d"
提示信息为:“Input student number(n<30):\n”
( 2 )录入每个学生的学号和考试成绩:
要求输入数据格式为:"%ld%f"
提示信息为:“Input student's ID and score:\n”
输出格式:
1、菜单项的输出显示:
Management for Students' scores
1.Input record
2.Calculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
2、计算课程的总分和平均分:
要求输出总分与平均分格式为:“sum=%.0f,aver=%.2f\n”
3、按成绩由高到低排出名次表:
要求输出格式为:"%ld\t%.0f\n"
提示信息为:“Sort in descending order by score:\n”
4、按学号由小到大排出成绩表:
要求输出格式为:"%ld\t%.0f\n"
提示信息为:“Sort in ascending order by number:\n”
5、按学号查询学生信息及其考试成绩(输出学号与成绩):
如果未查到此学号的学生,提示信息为:“Not found!\n”;
如果查询到该学生,要求输出格式为:"%ld\t%.0f\n"
6、按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,统计每个类别的人数以及所占的百分比:
成绩<60输出提示格式为:"<60\t%d\t%.2f%%\n";
成绩=100输出格式为:"%d\t%d\t%.2f%%\n";
其他要求输出百分比格式为:"%d-%d\t%d\t%.2f%%\n"
演示效果:


代码:
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
//宏定义最大学生人数
#define stu_max 30
/*进行函数的全局声明*/
//获取学生人数
int stu_num();
//显示菜单获取用户输入
char menu_tips();
//获取学生学号,及本门考试成绩
void stu_information(long num[],float score[],int n);
//计算输出课程的总分和平均分
void sum_aver(float score[],int n);
//模块功能:交换两个长整型数据
void exchange_long(long *a,long *b);
//模块功能:交换两个浮点型数据
void exchange_float(float *a,float *b);
//按成绩由高到低输出名次表
void output_score(long num[],float score[],int n);
//按学号从小到大排出成绩表
void output_num(long num[],float score[],int n);
//查询输出学生信息及考试成绩:
void query(long num[],float score[],int n);
//分数划界处理并输出
void score_pro(float score[],int n);
//直接输出对应列表
void output(long num[],float score[],int n);
//暂停清屏
void clean();
int main()
{
int n,i;
long num[stu_max];
float score[stu_max];
n=stu_num();
while(1)
{
i=menu_tips();
switch(i)
{
case '1':printf("1"),stu_information(num,score,n),system("cls");break;
case '2':printf("2"),sum_aver(score,n),clean();break;
case '3':printf("3"),output_score(num,score,n),clean();break;
case '4':printf("4"),output_num(num,score,n),clean();break;
case '5':printf("5"),query(num,score,n),clean();break;
case '6':printf("6"),score_pro(score,n),clean();break;
case '7':printf("7"),output(num,score,n),clean();break;
case '0':printf("0"),exit(0);break;
default:printf("Input error!\n"),clean();
}
}
}
/*以下为函数功能模块*/
//获取学生人数
int stu_num()
{
int n;
printf("Input student number(n<30):\n");
scanf("%d",&n);
system("cls");
return n;
}
//显示菜单获取用户输入
char menu_tips()
{
printf(" -----------------------------------------------------------\n");
printf("| Management for Students' scores |\n");
printf(" -----------------------------------------------------------\n");
printf("| 1.Input record |\n");
printf("| 2.Calculate total and average score of course |\n");
printf("| 3.Sort in descending order by score |\n");
printf("| 4.Sort in ascending order by numbe |\n");
printf("| 5.Search by number |\n");
printf("| 6.Statistic analysis |\n");
printf("| 7.List record |\n");
printf("| 0.Exit |\n");
printf(" -----------------------------------------------------------\n");
printf("\nPlease Input your choice:\n");
char i;
i=getch();
return i;
}
//获取学生学号,及本门考试成绩
void stu_information(long num[],float score[],int n)
{
int i;
printf("\nInput student's ID and score:\n");
for(i=0;i<n;i++)
scanf("%ld%f",&num[i],&score[i]);
}
//计算输出课程的总分和平均分
void sum_aver(float score[],int n)
{
int i;
float sum,aver;
for(i=0,sum=0;i<n;i++)
sum+=score[i];
aver=sum/n;
printf("\nsum=%.0f,aver=%.2f\n",sum,aver);
}
//模块功能:交换两个长整型数据
void exchange_long(long *a,long *b)
{
long t;
t=*a;
*a=*b;
*b=t;
}
//模块功能:交换两个浮点型数据
void exchange_float(float *a,float *b)
{
float t;
t=*a; *a=*b; *b=t;
}
//按成绩由高到低输出名次表
void output_score(long num[],float score[],int n)
{
int i,j;
for(j=n-1;j>0;j--)
{
for(i=0;i<j;i++)
if(score[i]<score[i+1])
{
exchange_float(&score[i],&score[i+1]);
exchange_long(&num[i],&num[i+1]);
}
}
printf("\nSort in descending order by score:");
output(num,score,n);
}
//按学号从小到大排出成绩表
void output_num(long num[],float score[],int n)
{
int i,j;
for(j=n-1;j>0;j--)
{
for(i=0;i<j;i++)
if(num[i]>num[i+1])
{
exchange_float(&score[i],&score[i+1]);
exchange_long(&num[i],&num[i+1]);
}
}
output(num,score,n);
}
//查询输出学生信息及考试成绩:
void query(long num[],float score[],int n)
{
printf("\nEnter the ID to query:\n");
long temp;
scanf("%ld",&temp);
int i;
for(i=0;i<n;i++)
{
if(num[i]==temp)
{
printf("%ld\t%.0f\n",num[i],score[i]);
return;
}
}
printf("\nNot found!\n");
}
//分数划界处理并输出
void score_pro(float score[],int n)
{
int t[6]={0,0,0,0,0,0};
/*前五个分别对应优秀、良好、中等、及格、不及格五个类别
第六位存储100分的人数*/
int i,m;
for(i=0;i<n;i++)
{
if(score[i]>=90&&score[i]<100) t[0]++;
if(score[i]>=80&&score[i]<=89) t[1]++;
if(score[i]>=70&&score[i]<=79) t[2]++;
if(score[i]>=60&&score[i]<=69) t[3]++;
if(score[i]>=0 &&score[i]<=59) t[4]++;
if(score[i]==100) t[5]++;
}
//遍历t数组,输出对应的数据
for(i=0,m=9;i<6;i++)
{
if(i==4)
printf("<60\t%d\t%.2f%%\n",t[4],(float)t[4]/n*100);
if(i==5)
printf("%d\t%d\t%.2f%%\n",100,t[5],(float)t[5]/n*100);
if(i!=4&&i!=5)
{
if(i==0)
printf("\n");
printf("%d-%d\t%d\t%.2f%%\n",m*10,m*10+9,t[i],(float)t[i]/n*100);
m--;
}
}
}
//直接输出对应列表
void output(long num[],float score[],int n)
{
int i;
for(i=0;i<n;i++)
{
if(i==0)
printf("\n");
printf("%ld\t%.0f\n",num[i],score[i]);
}
}
//暂停清屏
void clean()
{
system("pause");
system("cls");
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/kcyxws/article/details/105151639








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。