【id:395】【20分】B. 【课程设计】Add

题目原文

题目描述

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

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

追加若干个学生的成绩信息,输出新的数据库和学生总数。

要求编写函数 Add(name_f, name_l, id, score)

输入

追加信息

输出

新的成绩表

样例

输入样例1

Jingyuuuu LI 202200000900 59
Jingyuuuu Lous 202100000900 60

输出样例1

Name_f Name_l stu_id score retake GPA
Jingyu LI 202200000000 85 0 A
Jy LEE 202200100000 89 0 A
Jxxxyx Leeeee 202100100000 100 1 A+
Jingyu11 LI 202200000001 85 0 A
Jingyuuuu LI 202200000900 59 0 F
Jingyuuuu Lous 202100000900 60 1 D
Total: 6

提示

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

AC代码

#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 init()
{
    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");
}

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()
{
    init();

    char name_f[20], name_l[20], id[20];
    int score;
    int i = 4;
    while (~scanf("%s%s%s%d", name_f, name_l, id, &score))
    {
        if (strlen(id) != 12 || score < 0 || score > 100)
            continue;

        Add(name_f, name_l, id, score, i);

        get_gpa(i);

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

        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;
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值