C语言学生成绩管理系统 C语言实现简易学生成绩管理系统

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

C语言学生成绩管理系统 C语言实现简易学生成绩管理系统

子奕°   2021-01-28 我要评论

某班有最多不超过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"

演示效果:

代码:

#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");
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们