第9章实验1:学生成绩管理系统V2.0

简介: 第9章实验1:学生成绩管理系统V2.0

第9章实验1:学生成绩管理系统V2.0


(代码在最后面)


某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,参考前面章节的“学生成绩管理系统V1.0”,用一维数组和函数指针作函数参数编程实现如下菜单驱动的学生成绩管理系统:

(1)录入每个学生的学号和考试成绩;

(2)计算课程的总分和平均分;

(3)按成绩由高到低排出名次表;

(4)按成绩由低到高排出名次表;

(5)按学号由小到大排出成绩表;

(6)按学号查询学生排名及其考试成绩;

(7)按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(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”;

**如果查询到该学生,要求输出格式为:"%ld\t%.0f\n"

按优秀(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>
#include<stdlib.h>
#define N 30
main()
{
    int n, i, j, temp1, temp2, choice, p, mark;
    long ids;
    float sum;
    printf("Input student number(n<30):\n");
    while (scanf("%d", &n))
    {
        if (n < 30 && n > 0)
            break;
        else
        {
            printf("Invalid Input!");
            continue;
        }
    }
    long id[N];
    float score[N];
Choice:
    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 score\n");
    printf("5.Sort in ascending order by number\n");
    printf("6.Search by number\n");
    printf("7.Statistic analysis\n");
    printf("8.List record\n");
    printf("0.Exit\n");
    printf("Please Input your choice:\n");
    scanf("%d", &choice);
    getchar();
    switch (choice)
    {
    case 1:
        goto a;
    case 2:
        goto b;
    case 3:
        goto c;
    case 4:
        goto h;
    case 5:
        goto d;
    case 6:
        goto e;
    case 7:
        goto f;
    case 8:
        goto g;
    case 0:
        goto end;
    default:
        printf("Input error!\n");
        goto Choice;
    }
a:
    printf("Input student's ID and score:\n");
    for (i = 1; i <= n; i++)
    {
        scanf("%ld %f", &id[i], &score[i]);
        getchar();
    }
    goto Choice;
b:
    sum = 0;
    for (i = 1; i <= n; i++)
        sum = sum + score[i];
    printf("sum=%.0f,aver=%.2f\n", sum, sum / n);
    goto Choice;
c:
    printf("Sort in descending order by score:\n");
    for (i = 1; i < n; i++)
        for (j = i + 1; j <= n; j++)
            if (score[j] > score[i])
            {
                temp1 = score[i], temp2 = id[i];
                score[i] = score[j], id[i] = id[j];
                score[j] = temp1, id[j] = temp2;
            }
    for (i = 1; i <= n; i++)
        printf("%ld\t%.0f\n", id[i], score[i]);
    goto Choice;
d:
    printf("Sort in ascending order by number:\n");
    for (i = 1; i < n; i++)
        for (j = i + 1; j <= n; j++)
            if (id[i] > id[j])
            {
                temp1 = score[i], temp2 = id[i];
                score[i] = score[j], id[i] = id[j];
                score[j] = temp1, id[j] = temp2;
            }
    for (i = 1; i <= n; i++)
        printf("%ld\t%.0f\n", id[i], score[i]);
    goto Choice;
e:
    printf("Input the number you want to search:\n");
    scanf("%ld", &ids);
    getchar();
    for (i = 1; i <= n; i++)
    {
        if (ids == id[i])
        {
            printf("%ld\t%.0f\n", id[i], score[i]);
            goto Choice;
        }
        else
            continue;
    }
    printf("Not found!\n");
    goto Choice;
f:
    for (i = 5; i <= 10; i++)
    {
        p = 0;
        for (j = 1; j <= n; j++)
        {
            mark = score[j] < 60 ? 5 : (int)score[j] / 10;
            if (mark == i)
                p++;
        }
        if (i == 5)
        {
            printf("<60\t%d\t%.2f%%\n", p, (float)p / n * 100);
            continue;
        }
        else if (i >= 6 && i <= 9)
        {
            printf("%d-%d\t%d\t%.2f%%\n", i * 10, i * 10 + 9, p, (float)p / n * 100);
            continue;
        }
        else
            printf("%d\t%d\t%.2f%%\n", i * 10, p, (float)p / n * 100);
    }
    goto Choice;
g:
    for (i = 1; i <= n; i++)
        printf("%ld\t%.0f\n", id[i], score[i]);
    goto Choice;
h:
    printf("Sort in ascending order by score:\n");
    for (i = 1; i < n; i++)
        for (j = i + 1; j <= n; j++)
            if (score[j] < score[i])
            {
                temp1 = score[i], temp2 = id[i];
                score[i] = score[j], id[i] = id[j];
                score[j] = temp1, id[j] = temp2;
            }
    for (i = 1; i <= n; i++)
        printf("%ld\t%.0f\n", id[i], score[i]);
    goto Choice;
end:
    printf("End of program!\n");
    return 0;
}
相关文章
|
XML 编解码 Java
Spring Boot 中的 RestTemplate和Retrofit 插件很好
Spring Boot 中的 RestTemplate和Retrofit 插件很好
940 1
|
存储 算法 安全
【加密算法】AES对称加密算法简介
【加密算法】AES对称加密算法简介
|
移动开发 小程序 JavaScript
uniapp中uview组件库的Input 输入框 的使用方法
uniapp中uview组件库的Input 输入框 的使用方法
2996 0
|
JSON 数据可视化 Java
Spring Boot中使用Swagger3.0.0版本构建RESTful APIs
Spring Boot中使用Swagger3.0.0版本构建RESTful APIs
543 6
|
IDE Java 程序员
学生邮箱白嫖/免费安装JetBrains全家桶(IDEA/pycharm等) —— 保姆级教程
本文提供了如何使用学生邮箱免费获取并安装JetBrains全家桶(包括IDEA、PyCharm等)的详细教程,涵盖了学生认证、软件下载、安装及常见问题的解决方法。
9132 0
学生邮箱白嫖/免费安装JetBrains全家桶(IDEA/pycharm等) —— 保姆级教程
|
算法 Java 计算机视觉
【图像去模糊】非盲去模糊实景图像处理,使用点扩散函数(PSF)快速去除实景图像中的模糊(Matlab代码实现)
【图像去模糊】非盲去模糊实景图像处理,使用点扩散函数(PSF)快速去除实景图像中的模糊(Matlab代码实现)
836 2
Altium Designer中编译原理图之后出现 off grid at..... 的解决方法
Altium Designer中编译原理图之后出现 off grid at..... 的解决方法
1803 0
|
存储 人工智能 安全
业财一体 ERP 数智化管理系统
业财一体 ERP 数智化管理系统是基于钉钉 + 钉钉低代码构建,作为企业管理体系数字化转型升级的驱动器,目标是将业务管理与财务管理深度融合,帮助企业构建一个集成、高效、智能的管理体系。旨在通过先进的信息技术,打通各业务模块数据传递链路,进行业务财务的一体化管理,采取智能化手段大幅度提升工作效率,逐步实现企业数字化转型和智能化改造。
1110 12
|
存储 供应链 数据建模
供应链场景使用ClickHouse最佳实践
在供应链管理中,ClickHouse凭借其高性能查询、高压缩比和实时数据处理能力,能够显著提升数据处理和分析的效率。通过合理的数据建模、优化实践和性能调优,可以充分发挥ClickHouse的优势,为供应链管理提供强有力的支持。
516 12
|
机器学习/深度学习 存储 人工智能
生成式 AI 与 LangCHain(一)(1)
生成式 AI 与 LangCHain(一)
1038 1