学生成绩管理系统V1.0(C语言)

题目要求:

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,用一维数组作函数参数编程实现如下学生成绩管理:
(1)录入每个学生的学号和考试成绩;
(2)计算课程的总分和平均分;
(3)按成绩由高到低排出名次表;
(4)按学号由小到大排出成绩表;
(5)按学号查询学生排名及其考试成绩;
(6)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;
(7)输出每个学生的学号、考试成绩。

程序运行结果示例:
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 number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
1↙
Input student's ID, name 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 number
5.Search by number
6.Statistic analysis
7.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 number
5.Search by number
6.Statistic analysis
7.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 number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
4↙
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 number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
5↙
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 number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
6↙
<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 number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
7↙
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 number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
8↙
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 number
5.Search by number
6.Statistic analysis
7.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, name and score:\n"
输出格式:
菜单项的输出显示:
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 number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:
计算课程的总分和平均分:
              **输出总分与平均分格式:"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 number:\n"
按学号查询学生排名及其考试成绩:
               **如果未查到此学号的学生,提示信息:"Not found!\n"
               **如果查询到该学生,输出格式:"%ld\t%.0f\n"
按优秀(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>
#define   STU_NUM 30       /* 最多的学生人数 */
int   Menu(void);
void  ReadScore(long num[], float score[], int n);
void  AverSumofScore(float score[], int n);
void  DeSortbyScore(long num[], float score[], int n);
void  AsSortbyNum(long num[], float score[], int n);
void  SearchbyNum(long num[], float score[], int n);
void  StatisticAnalysis(float score[], int n);
void  PrintScore(long num[], float score[], int n) ;
int main()
{ 	 	 		  	
    char   itemSelected;
    int    n = 0;
    float score[STU_NUM];
    long   num[STU_NUM];
    printf("Input student number(n<30):\n");
    scanf("%d", &n);
    while (1)
    { 	 	 		  	
        itemSelected = Menu();	/* 显示菜单,并读取用户输入 */
        switch (itemSelected)
        { 	 	 		  	
        case 1:
            ReadScore(num, score, n);
            break;
        case 2:
            AverSumofScore(score, n);
            break;
        case 3:
            DeSortbyScore(num, score, n);
            printf("Sort in descending order by score:\n");
            PrintScore(num, score, n);
            break;
        case 4:
            AsSortbyNum(num, score, n);
            printf("Sort in ascending order by number:\n");
            PrintScore(num, score, n);
            break;
        case 5:
            SearchbyNum(num, score, n);
            break;
        case 6:
            StatisticAnalysis(score, n);
            break;
        case 7:
            PrintScore(num, score, n);
            break;
        case 0:
            printf("End of program!");
            exit(0);
        default:
            printf("Input error!\n");
        }
    }
    return 0;
} 	 	 		  	
/*  函数功能:显示菜单并获得用户键盘输入的选项 */
int Menu(void)
{ 	 	 		  	
    int itemSelected;
    printf("Management for Students' scores\n");
    printf("1.Input record\n");
    printf("2.Caculate total and average score of course\n");
    printf("3.Sort in descending order by score\n");
    printf("4.Sort in ascending order by number\n");
    printf("5.Search by number\n");
    printf("6.Statistic analysis\n");
    printf("7.List record\n");
    printf("0.Exit\n");
    printf("Please Input your choice:\n");
    scanf("%d", &itemSelected); 	/* 读入用户输入 */
    return itemSelected;
} 	 	 		  	
/* 函数功能:输入n个学生的某门课成绩 */
void ReadScore(long num[], float score[], int n)
{ 	 	 		  	
    int i;
    printf("Input student's ID, name and score:\n");
    for (i = 0; i < n; i++)
    { 	 	 		  	
        scanf("%ld%f", &num[i], &score[i]);
    }
} 	 	 		  	
/* 函数功能:计算全班总分和平均分 */
void AverSumofScore(float score[], int n)
{ 	 	 		  	
    int    i;
    float  sum = 0;
    for (i = 0; i < n; i++)
    { 	 	 		  	
        sum = sum + score[i];
    }
    printf("sum=%.0f,aver=%.2f\n", sum, n > 0 ? sum / n : 0);
} 	 	 		  	
/* 函数功能:按选择法将数组score的元素值按从高到低排序 */
void DeSortbyScore(long num[], float score[], int n)
{ 	 	 		  	
    int     i, j, k;
    float  temp1;
    long   temp2;
    for (i = 0; i < n - 1; i++)
    { 	 	 		  	
        k = i;
        for (j = i + 1; j < n; j++)
        { 	 	 		  	
            if (score[j] > score[k]) k = j;
        }
        if (k != i)
        { 	 	 		  	
            /* 交换成绩 */
            temp1 = score[k];
            score[k] = score[i];
            score[i] = temp1;
            /* 交换学号 */
            temp2 = num[k];
            num[k] = num[i];
            num[i] = temp2;
        }
    }
} 	 	 		  	
/* 函数功能:按选择法将数组num的元素值按从低到高排序 */
void AsSortbyNum(long num[], float score[], int n)
{ 	 	 		  	
    int     i, j, k;
    float  temp1;
    long   temp2;
    for (i = 0; i < n - 1; i++)
    { 	 	 		  	
        k = i;
        for (j = i + 1; j < n; j++)
        { 	 	 		  	
            if (num[j] < num[k])  k = j;
        }
        if (k != i)
        { 	 	 		  	
            /* 交换成绩 */
            temp1 = score[k];
            score[k] = score[i];
            score[i] = temp1;
            /* 交换学号 */
            temp2 = num[k];
            num[k] = num[i];
            num[i] = temp2;
        }
    }
} 	 	 		  	
/* 函数功能:按学号查找学生成绩并显示查找结果 */
void SearchbyNum(long num[], float score[], int n)
{ 	 	 		  	
    long number;
    int   i;
    printf("Input the number you want to search:\n");
    scanf("%ld", &number);
    for (i = 0; i < n; i++)
    { 	 	 		  	
        if (num[i] == number)
        { 	 	 		  	
            printf("%ld\t%.0f\n", num[i], score[i]);
            return;
        }
    }
    printf("Not found!\n");
} 	 	 		  	
/* 函数功能:统计各分数段的学生人数及所占的百分比 */
void StatisticAnalysis(float score[], int n)
{ 	 	 		  	
    int  i, total, t[6] = {0, 0, 0, 0, 0, 0};
    for (i = 0; i < n; i++)
    { 	 	 		  	
        if (score[i] >= 0 && score[i] < 60) t[0]++;
        else if (score[i] < 70)             t[1]++;
        else if (score[i] < 80)             t[2]++;
        else if (score[i] < 90)             t[3]++;
        else if (score[i] < 100)            t[4]++;
        else if (score[i] == 100)         t[5]++;
    }
    for (total = 0, i = 0; i <= 5; i++)
    { 	 	 		  	
        total = total + t[i];
    }
    for (i = 0; i <= 5; i++)
    { 	 	 		  	
        if (i == 0)
        { 	 	 		  	
            printf("<60\t%d\t%.2f%%\n", t[i], (float)t[i] / n * 100);
        }
        else if (i == 5)
        { 	 	 		  	
            printf("%d\t%d\t%.2f%%\n", (i + 5) * 10, t[i], (float)t[i] / n * 100);
        }
        else
        { 	 	 		  	
            printf("%d-%d\t%d\t%.2f%%\n", (i + 5) * 10, (i + 5) * 10 + 9, t[i],
                   (float)t[i] / n * 100);
        }
    }
} 	 	 		  	
/* 函数功能: 打印学生成绩 */
void PrintScore(long num[], float score[], int n)
{ 	 	 		  	
    int i;
    for (i = 0; i < n; i++)
    { 	 	 		  	
        printf("%ld\t%.0f\n", num[i], score[i]);
    }
} 

下面是我自己写的(写得不是很好见谅):

#include "stdio.h"
#include <stdlib.h>

typedef struct student
{
    long int stu_ID;
    float score;
}STUDENT;

STUDENT Input_stu(STUDENT stu_info[],int n);//录入成绩
void Sum_Avg_Score(STUDENT stu_score[],int n);//计算平均分和总分
void ScoreHightoLow(STUDENT stu_score[],int n);//成绩由高到低输出
void IdStoLarge(STUDENT stu_id[],int n);//学号由小到大输出
void Find_student(STUDENT stu_info[],int n);//查询成绩
void Stat_analysis(STUDENT statistic[],int n);//按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;
void Output_info(STUDENT stu_info[],int n);//输出每个学生的学号、考试成绩

void main()
{
    int stu_num,select;
    printf("Input student number(n<30):\n");
    scanf("%d",&stu_num);
    STUDENT stu[stu_num];
    do
    {
        printf("Management for Students' scores\n");
        printf("1.Input record\n");
        printf("2.Caculate total and average score of course\n");
        printf("3.Sort in descending order by score\n");
        printf("4.Sort in ascending order by number\n");
        printf("5.Search by number\n");
        printf("6.Statistic analysis\n");
        printf("7.List record\n");
        printf("0.Exit\n");
        printf("Please Input your choice:\n");
        scanf("%d",&select);
        switch (select)
        {
        case 1:
            Input_stu(stu,stu_num);
            break;
        case 2:
            Sum_Avg_Score(stu,stu_num);
            break;
        case 3:
            ScoreHightoLow(stu,stu_num);
            break;
        case 4:
            IdStoLarge(stu,stu_num);
            break;
        case 5:
            Find_student(stu,stu_num);
            break;
        case 6:
            Stat_analysis(stu,stu_num);
            break;
        case 7:
            Output_info(stu,stu_num);
            break;
        case 0:
            printf("End of program!\n");
            break;    
        default:
            printf("Input error!\n");
            break;
        }
    } while (select!=0);
    
}

STUDENT Input_stu(STUDENT stu_info[],int n)//输入每个学生的数据
{
    int i;
    printf("Input student's ID, name and score:\n");
    for(i=0;i<n;i++)
    {
        scanf("%ld%f",&stu_info[i].stu_ID,&stu_info[i].score);
        getchar();//清空缓冲区
    }
    return *stu_info;
}

void Sum_Avg_Score(STUDENT stu_score[],int n)//求输入的所有学生的总分和平均分
{
    float sum=0;
    int i;
    for(i=0;i<n;i++)
    {
        sum+=stu_score[i].score;
    }
    printf("sum=%.0f,aver=%.2f\n",sum,sum/n);
}

void ScoreHightoLow(STUDENT stu_score[],int n)//按分数由高到低输出
{
    int i,j;
    float temp1;
    long int temp2;
    printf("Sort in descending order by score:\n");
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-1-i;j++)
        {
            if(stu_score[j+1].score>stu_score[j].score)
            {
                temp1=stu_score[j+1].score,temp2=stu_score[j+1].stu_ID;
                stu_score[j+1].score=stu_score[j].score,stu_score[j+1].stu_ID=stu_score[j].stu_ID;
                stu_score[j].score=temp1,stu_score[j].stu_ID=temp2;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%ld\t%.0f\n",stu_score[i].stu_ID,stu_score[i].score);
    }
}

void IdStoLarge(STUDENT stu_id[],int n)//按学号由小到大输出
{
    int i,j;
    float temp1;
    long int temp2;
    printf("Sort in ascending order by number:\n");
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-1-i;j++)
        {
            if(stu_id[j].stu_ID>stu_id[j+1].stu_ID)
            {
                temp1=stu_id[j].score,temp2=stu_id[j].stu_ID;
                stu_id[j].score=stu_id[j+1].score,stu_id[j].stu_ID=stu_id[j+1].stu_ID;
                stu_id[j+1].score=temp1,stu_id[j+1].stu_ID=temp2;
            }
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%ld\t%.0f\n",stu_id[i].stu_ID,stu_id[i].score);
    }
}

void Find_student(STUDENT stu_info[],int n)//输入学号查找学生的资料
{
    int i;
    long int ids;
    printf("Input the number you want to search:\n");
    scanf("%ld",&ids);
    for(i=0;i<n;i++)
    {
        if(ids==stu_info[i].stu_ID)
        {
            printf("%ld\t%.0f\n",stu_info[i].stu_ID,stu_info[i].score);
            return ;
        }
        else
            continue;
    }
    printf("Not found!\n");
    return ;
}

void Stat_analysis(STUDENT statistic[],int n)//数据分析,每一个分数段的比例
{
    int  i,total,t[6]={0,0,0,0,0,0};
    for (i=0;i<n;i++)
    { 	 	 		  	
        if(statistic[i].score>=0&&statistic[i].score<60)t[0]++;
        else if (statistic[i].score<70)             t[1]++;
        else if (statistic[i].score<80)             t[2]++;
        else if (statistic[i].score<90)             t[3]++;
        else if (statistic[i].score<100)            t[4]++;
        else if (statistic[i].score==100)         t[5]++;
    }
    for(total=0,i=0;i<=5;i++)
    { 	 	 		  	
        total=total+t[i];
    }
    for(i=0;i<=5;i++)
    { 	 	 		  	
        if(i==0)
        { 	 	 		  	
            printf("<60\t%d\t%.2f%%\n",t[i],(float)t[i]/n*100);
        }
        else if (i == 5)
        { 	 	 		  	
            printf("%d\t%d\t%.2f%%\n",(i+5)*10,t[i],(float)t[i]/n*100);
        }
        else
        { 	 	 		  	
            printf("%d-%d\t%d\t%.2f%%\n",(i+5)*10,(i+5)*10+9,t[i],
                   (float)t[i]/n*100);
        }
    }
}

void Output_info(STUDENT stu_info[],int n)//输出学生的信息和分数
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("%ld\t%.0f\n",stu_info[i].stu_ID,stu_info[i].score);
    }
}

  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值