学生成绩管理系统V1.0

题目描述

某班有最多不超过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"
输出学生成绩格式:"%ld\t%.0f\n"

思路

1、采用结构体存储每一位学生的信息
2、采用动态链表存储所有学生
3、排序采用冒泡算法
4、独立封装每个功能函数,可扩展性强

代码

/*
Author:UserHAO 
FROM CQUPT
THANKS FOR XDY
*/
#include <stdlib.h>
#include<stdio.h>

typedef struct Student_Node
{
    long ID;
    float score;
    struct Student_Node* next;
} Student_Node, * STU_List;

void Initialize(STU_List* S)
{
    *S = (STU_List)malloc(sizeof(Student_Node));
    (*S)->ID = 0;
    (*S)->score = 0;
    (*S)->next = NULL;
}

void Input_record(STU_List* S, int n)
{
    STU_List p;
    printf("Input student's ID, name and score:\n");
    for (int i = 0; i < n; i++)
    {
        p = (STU_List)malloc(sizeof(Student_Node));
        scanf_s("%ld%f", &(p->ID), &(p->score));
        p->next = (*S)->next;//p成了末尾节点
        (*S)->next = p;//把这个新节点接到前节点之后
    }
}

void Print_stu(STU_List S)
{
    STU_List p = S->next;
    while (p)
    {
        printf("%ld\t%.0f\n", p->ID, p->score);
        p = p->next;
    }
}

void Total_average_score(STU_List* S, int n)
{
    float total = 0;
    STU_List p = (*S)->next;
    while (p)
    {
        total = p->score + total;
        p = p->next;
    }
    printf("sum=%.0f,aver=%.2f\n", total, total / n);
}

void Sort_score(STU_List* S, short int n)
{
    STU_List p, q, temp;
    short int times;
    for (int i = 0; i < n - 1; i++)
    {
        p = (*S)->next;
        q = (*S)->next->next;
        temp = (*S);
        times = n - 1 - i;
        while (times)
        {
            if (p->score < q->score)
            {
                p->next = q->next;
                q->next = p;
                temp->next = q;
            }
            temp = temp->next;
            p = temp->next;
            q = temp->next->next;
            times--;
        }
    }
    printf("Sort in descending order by score:\n");
    Print_stu(*S);
}

void Sort_number(STU_List* S, short int n)
{
    STU_List p, q, temp;
    short int times;
    for (int i = 0; i < n - 1; i++)
    {
        p = (*S)->next;
        q = (*S)->next->next;
        temp = (*S);
        times = n - 1 - i;
        while (times)
        {
            if (p->ID > q->ID)
            {
                p->next = q->next;
                q->next = p;
                temp->next = q;
            }
            temp = temp->next;
            p = temp->next;
            q = temp->next->next;
            times--;
        }
    }
    printf("Sort in ascending order by number:\n");
    Print_stu(*S);
}

void Search_score(STU_List S)
{
    STU_List p = S->next;
    long ID;
    printf("Input the number you want to search:\n");
    scanf_s("%ld", &ID);
    while (p)
    {
        if (p->ID == ID)
        {
            printf("%ld\t%.0f\n", ID, p->score);
            break;
        }
        else
        {
            p = p->next;
        }
    }
    if (!p)
    {
        printf("Not found!\n");
    }
}

void Analysis_score(STU_List S, short int n)
{
    STU_List p = S->next;
    float temp_score10 = 0, temp_score9 = 0, temp_score8 = 0, temp_score7 = 0, temp_score6 = 0, temp_score5 = 0;
    float num = n;
    while (p)
    {
        if (p->score == 100)
            temp_score10++;
        else if (90 <= p->score && p->score <= 99)
            temp_score9++;
        else if (80 <= p->score && p->score <= 89)
            temp_score8++;
        else if (70 <= p->score && p->score <= 79)
            temp_score7++;
        else if (60 <= p->score && p->score <= 69)
            temp_score6++;
        else if (p->score < 60)
            temp_score5++;
        p = p->next;
    }
    printf("<60\t%d\t%.2f%%\n", (int)temp_score5, (temp_score5 / num) * 100.0);
    printf("%d-%d\t%d\t%.2f%%\n", 60, 69, (int)temp_score6, (temp_score6 / num) * 100.0);
    printf("%d-%d\t%d\t%.2f%%\n", 70, 79, (int)temp_score7, (temp_score7 / num) * 100.0);
    printf("%d-%d\t%d\t%.2f%%\n", 80, 89, (int)temp_score8, (temp_score8 / num) * 100.0);
    printf("%d-%d\t%d\t%.2f%%\n", 90, 99, (int)temp_score9, (temp_score9 / num) * 100.0);
    printf("%d\t%d\t%.2f%%\n", 100, (int)temp_score10, (temp_score10 / num) * 100.0);
}

void print_menu()
{
    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");
}

void choose(short int choice, STU_List* S, short int n)
{
    switch (choice)
    {
    case 1:
        Input_record(S, n);
        break;
    case 2:
        Total_average_score(S, n);
        break;
    case 3:
        Sort_score(S, n);
        break;
    case 4:
        Sort_number(S, n);
        break;
    case 5:
        Search_score(*S);
        break;
    case 6:
        Analysis_score(*S, n);
        break;
    case 7:
        Print_stu(*S);
        break;
    default:
        printf("Input error!\n");
        break;
    }

}

int main()
{
    short int n, choice;
    STU_List S;
    Initialize(&S);
    printf("Input student number(n<30):\n");
    scanf_s("%hd", &n);

    while (1)
    {
        print_menu();
        printf("Please Input your choice:\n");
        scanf_s("%hd", &choice);
        if (choice == 0)
        {
            printf("End of program!\n");
            break;
        }
        else
        {
            choose(choice, &S, n);
        }
    }
    return 0;
}

学生样例

学号分数
1100300187
1100300598
1100300375
1100300248
1100300465
11003006100
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值