c语言课程设计第二关Add

任务描述

现在你的数据库里已经存储了以下信息:

 
  1. Name_f Name_l stu_id score retake GPA
  2. Jingyu LI 202200000000 85 0 A
  3. Jy LEE 202200100000 89 0 A
  4. Jxxxyx Leeeee 202100100000 100 1 A+
  5. Jingyu11 LI 202200000001 85 0 A

追加若干个学生的成绩信息,输出新的数据库和学生总数。 要求编写函数 Add(name_f, name_l, id, score)

编程要求

根据提示,在右侧编辑器补充代码,完成学生信息追加。

测试说明

输入说明: 追加信息。

输出说明: 输出新的新的成绩表。

注意:需要过滤掉不合法输入:成绩不在0~100区间内的;学号不是12位的。

平台会对你编写的代码进行测试:

测试输入: Jingyuuuu LI 202200000900 59 Jingyuuuu Lous 202100000900 60 预期输出:

 
  1. Name_f Name_l stu_id score retake GPA
  2. Jingyu LI 202200000000 85 0 A
  3. Jy LEE 202200100000 89 0 A
  4. Jxxxyx Leeeee 202100100000 100 1 A+
  5. Jingyu11 LI 202200000001 85 0 A
  6. Jingyuuuu LI 202200000900 59 0 F
  7. Jingyuuuu Lous 202100000900 60 1 D
  8. Total: 6
  9. 代码实现:

    #include <stdio.h>

    #include <string.h>

    struct Information

    {

        char first_name[20];

        char last_name[20];

        char id[20];

        int score;

        int retake;

        char GPA[5];//定义结构体

    } stu[110] = {

        {"Jingyu", "LI", "202200000000", 85, 0, "A"},

        {"Jy", "LEE", "202200100000", 89, 0, "A"},

        {"Jxxxyx", "Leeeee", "202100100000", 100, 1, "A+"},

        {"Jingyu11", "LI", "202200000001", 85, 0, "A"}};//数据库已有内容

    char gpa[][5] = {{""}, {"A+"}, {"A"}, {"B+"}, {"B"}, {"C+"}, {"C"}, {"D"}, {"F"}};

    char check_id[] = {"2022"};

    void get_gpa(int i)

    {

        if (stu[i].score >= 93)

            strcpy(stu[i].GPA, "A+");

        else if (stu[i].score >= 85)

            strcpy(stu[i].GPA, "A");

        else if (stu[i].score >= 80)

            strcpy(stu[i].GPA, "B+");

        else if (stu[i].score >= 75)

            strcpy(stu[i].GPA, "B");

        else if (stu[i].score >= 70)

            strcpy(stu[i].GPA, "C+");

        else if (stu[i].score >= 65)

            strcpy(stu[i].GPA, "C");

        else if (stu[i].score >= 60)

            strcpy(stu[i].GPA, "D");

        else

            strcpy(stu[i].GPA, "F");

    }//成绩判定函数

    void Add(char name_f[], char name_l[], char id[], int score, int i)

    {

        strcpy(stu[i].first_name, name_f);

        strcpy(stu[i].last_name, name_l);

        strcpy(stu[i].id, id);

        stu[i].score = score;

    }//添加学生信息函数

    int main()

    {

        printf("Name_f Name_l stu_id score retake GPA\n");

        printf("Jingyu LI 202200000000 85 0 A\n");

        printf("Jy LEE 202200100000 89 0 A\n");

        printf("Jxxxyx Leeeee 202100100000 100 1 A+\n");

        printf("Jingyu11 LI 202200000001 85 0 A\n");

        char name_first[20], name_last[20], id[20];

        int score;

        int i = 4;

        while (~scanf("%s%s%s%d", name_first, name_last, id, &score))

        {

            if (strlen(id) != 12 || score < 0 || score > 100)

                continue;//排除错误信息

            Add(name_first, name_last, id, score, i);

            get_gpa(i);

            if (memcmp(stu[i].id, check_id, 4) != 0)

                stu[i].retake = 1;//memcmp函数用于比较内存区域buf1和buf2的前count个字节,相等就输出0,所以这里不相等就说明他不是2022的学生,也就是重修的

            printf("%s %s %s %d %d %s\n", stu[i].first_name, stu[i].last_name, stu[i].id, stu[i].score, stu[i].retake, stu[i].GPA);

            i++;

        }

        printf("Total: %d", i);

        return 0;

    }

 

  • 37
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值