第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;
}
相关文章
|
机器学习/深度学习 人工智能 自然语言处理
【医学知识图谱构建】基于有监督对比学习的上下位关系预测
背景 & 挑战(Background & Challenge)随着人工智能和医疗行业的蓬勃发展,各种医疗知识库与医疗知识图谱的构建已成为精准医学领域的研究热点。大数据时代,随着医疗系统的信息化发展,医疗领域已经积累了海量的数据。医疗知识图谱所具有的数据集成能力和知识推理能力能够将大量的医疗数据进行有序整合并应用到各类医疗场景中。目前在医疗领域,国外已经构建了一些知识库,比如医学主题
1849 1
【医学知识图谱构建】基于有监督对比学习的上下位关系预测
|
编译器 Linux 调度
makfile的编译选项:CFLAGS、CPPFLAGS、LDFLAGS、LIBS
makfile的编译选项:CFLAGS、CPPFLAGS、LDFLAGS、LIBS
3119 0
|
Java UED
Java中的异常处理:从基础到进阶
【10月更文挑战第40天】在Java编程的海洋中,异常处理是一艘必不可少的救生艇。它不仅保证了程序的健壮性,还提升了用户体验。本文将带你从异常处理的基础概念出发,逐步深入到高级技巧,让你在遇到风浪时能够从容应对。我们将通过实际代码示例,探讨如何在Java中优雅地处理异常,确保你的代码既清晰又高效。准备好了吗?让我们一起启航,探索Java异常处理的奥秘!
|
关系型数据库 MySQL
解决MySQL insert出现Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘xxx‘ at row 1
解决MySQL insert出现Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘xxx‘ at row 1
1133 2
|
Prometheus 监控 Cloud Native
Prometheus 社区与生态发展
【8月更文第29天】Prometheus 是一个开源的监控系统和时间序列数据库,以其简单易用、高性能的特点受到了广泛欢迎。自 2012 年成立以来,Prometheus 社区迅速壮大,形成了一个庞大且活跃的技术生态系统。本文将探讨 Prometheus 社区的发展趋势、相关项目和工具,以及如何参与贡献。
435 2
|
IDE 测试技术 开发工具
如何利用 HBuilderX 制作图文混排的网页
如何利用 HBuilderX 制作图文混排的网页
589 3
|
存储 Java 关系型数据库
基于Java和MySQL实现的大学生学籍管理系统(毕业设计附完整项目代码)
基于Java和MySQL实现的大学生学籍管理系统(毕业设计附完整项目代码)
2426 0
基于Java和MySQL实现的大学生学籍管理系统(毕业设计附完整项目代码)
|
存储 算法 搜索推荐
嵌入式软件中常见的 8 种数据结构详解
嵌入式软件中常见的 8 种数据结构详解
324 0
|
存储 机器学习/深度学习 人工智能
向量数据库简介和5个常用的开源项目介绍
在人工智能领域,有大量的数据需要有效的处理。随着我们对人工智能应用,如图像识别、语音搜索或推荐引擎的深入研究,数据的性质变得更加复杂。这就是向量数据库发挥作用的地方。与存储标量值的传统数据库不同,向量数据库专门设计用于处理多维数据点(通常称为向量)。这些向量表示多个维度的数据,可以被认为是指向空间中特定方向和大小的箭头。
4329 1

热门文章

最新文章