189 8069 5689

高级程序设计(大一教材)第八/8章实验学生成绩管理系统-创新互联

专注于为中小企业提供做网站、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业宜都免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

本人是大一新生刚刚学习c语言不久,感觉写到这个东西还是有些吃力,特地分享一下自己的代码和心得。(大一学生刚接触编程能力有限 仅限初学者交流沟通)

先放代码(编程环境vs2019)

#define _CRT_SECURE_NO_WARNINGS 1
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int  n = 0;
struct student
{
    unsigned long long num;
    char name[30];
    float score;
    float sum;
    float aver;
};
void shurushuju(struct student stu[], int n);
void sumandave(struct student stu[], int n);
void third(struct student stu[], int n);
void four(struct student stu[], int n);
void chaxun(struct student stu[], int n);
void fenxi(struct student stu[], int n);


int main(void)
{
    struct student stu[30];
    printf("请输入学生人数:");
    scanf("%d", &n);
    while (1)
    {
        int A = 0;
        printf("                               欢迎来到  《《《《天工大成绩管理系统》》》》\n");
        printf("                                 ************************************************\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("                                 ************************************************\n");
        printf("                                 请输入你的选择序号:");
        scanf("%d", &A);
        switch (A)
        {
        case 1:
            shurushuju(stu, n);
            break;
        case 2:
            sumandave(stu, n);
            break;
        case 3:
            third(stu, n);
            break;
        case 4:
            four(stu, n);
            break;
        case 5:
            chaxun(stu, n);
            break;
        case 6:
            fenxi(stu, n);
            break;
        case 0:
            exit(0);
        default:printf("error");
        }
    }
    return 0;
}
//输入基础数据到结构体里
void shurushuju(struct student stu[], int n)
{
    int i = 0;
    printf("输入学号 姓名 成绩:\n");
    for (i = 0;i< n;i++)
    {
        scanf("%lld %s %f", &stu[i].num, stu[i].name, &stu[i].score);
        printf("%lld,%s,%.1f已录入!", stu[i].num, stu[i].name, stu[i].score);
        getchar();
    }
}
//负责计算总和以及平均数
void sumandave(struct student stu[], int n)
{
    float stuTemp1 = 0;
    float aver1;
    int j;
    for (j = 0;j< n;j++)
    {
        stuTemp1 += stu[j].score;
    };
    aver1 = stuTemp1 / n;
    printf("总和是%.1f 平均分是%.1f\n", stuTemp1, aver1);
    getchar();
}
//冒泡排序 刚学会
void third(struct student stu[], int n)
{
    int i, j;
    struct student stuTemp;
    for (i = 0;i< n - 1;i++)
    {
        for (j = 0;j< n - 1 - i;j++)
        {
            if ((stu[j].score)< (stu[j + 1].score))
            {
                stuTemp = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = stuTemp;
            }
        }
    }
    for (i = 0; i< n; i++)
    {
        printf("%lld %s %.1f\n", stu[i].num, stu[i].name, stu[i].score);
    }
}

//按照学号从小到大排列成绩表
void four(struct student stu[], int n)
{
    int i, j;
    struct student stuTemp2;
    for (i = 0;i< n - 1;i++)
    {
        for (j = 0;j< n - 1 - i;j++)
        {
            if ((stu[j].num) >(stu[j + 1].num))
            {
                stuTemp2 = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = stuTemp2;
            }
        }
    }
    for (i = 0; i< n; i++)
    {
        printf("%lld %s %.1f\n", stu[i].num, stu[i].name, stu[i].score);
    }
}
//通过学号查询学生成绩等信息
void chaxun(struct student stu[], int n)
{
    unsigned long long point;
    int i = 1;
    int j = 0;
    while (i)
    {
        printf("请先输入学号");
        scanf("%lld", &point);
        for (j = 0;j< n;j++)
        {
            if (point == stu[j].num)
            {
                printf("%lld %s %.1f\n", stu[j].num, stu[j].name, stu[j].score);
            }
        }
    }
}
//分析一波
void fenxi(struct student stu[], int n)
{
    int A = 0, B = 0, C = 0, D = 0, E = 0, i = 0;
    for (i = 0;i< n;i++)
    {
        if (stu[i].score<= 100 && stu[i].score >= 90)
            A++;
        if (stu[i].score<= 89 && stu[i].score >= 80)
            B++;
        if (stu[i].score<= 79 && stu[i].score >= 70)
            C++;
        if (stu[i].score<= 69 && stu[i].score >= 60)
            D++;
        if (stu[i].score<= 59 && stu[i].score >= 0)
            E++;

    }
    printf("每个类别的人数有\nA:%d人\nB:%d人\nC:%d人\nD:%d人\nE:%d人\n  ", A, B, C, D, E);
    float a = 0, b = 0, c = 0, d = 0, e = 0;
    a = 100 * A / n;
    b = 100 * B / n;
    c = 100 * C / n;
    d = 100 * D / n;
    e = 100 * E / n;
    printf("每个类别所占百分比是\nA:%.1f%%\nB:%.1f%%\nC:%.1f%%\nD:%.1f%%\nE:%.1f%%\n", a, b, c, d, e);
}

涉及到一些知识点

比如说

1冒泡排序

2使用类似stu[i].score 去获取结构体的数据

3名字是用字符串类型定义的 字符串都是使用数组 所以定义结构体一开始name都有[] 一开始不太清楚胡乱去加没有理解清楚其中的意义

4因为我们学校学号位数超越了长整型 一开始一直乱码 所以选用了更大的unsigined long long 后续输出符也注意是%lld

最后欢迎初学者一起交流

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


本文题目:高级程序设计(大一教材)第八/8章实验学生成绩管理系统-创新互联
文章来源:http://cdxtjz.cn/article/dipghc.html

其他资讯