【id:394】【10分】A. 【课程设计】 Init

题目原文

题目描述

你需要将一系列的学生期末考试信息进行存储(学生人数不会超过100)。每个学生的信息包括:

姓名(由 first name 和last name 两部分组成,例如Jingyu LI,first_name = “Jingyu” last_name = “LI”) ;
学号(12 位数字组成,开头4位为2022、2021、2020);
C语言成绩(一个大于等于零的整数);
重修信息(学号 2022…为否,其余为是);

GPA等级(A+, A, B+, B, C+, C, D, F )。
A+: 100-93;
A: 92-85;
B+: 84-80;
B: 79-75;
C+:74-70;
C: 69-65;
D: 64-60;
F: <60.

其中,姓名,学号,成绩为输入数据,其余数据需要你计算。

另外,学号不符合规定的数据需要删除掉。

输入

一系列 名、姓、学号、成绩

输出

名、姓、学号、成绩、重修信息、GPA等级

样例

输入样例1

Jingyu LI 202200000000 85
Jy LEE 202200100000 89
Jxxxyx Leeeee 202000100000 100
Geinyu LEE 20220000 89
Jingyu11 LI 202200000001 85

输出样例1

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

提示

Geinyu LEE 20210000 89 不合法,需删掉。

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];

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");
}

int main()
{
    printf("Name_f Name_l stu_id score retake GPA rank\n");

    for (int i = 0; ~scanf("%s%s%s%d", stu[i].first_name, stu[i].last_name, stu[i].id, &stu[i].score); i++)
    {
        if (strlen(stu[i].id) != 12)
        {
            i--;
            continue;
        }

        get_gpa(i);

        if (memcmp(stu[i].id, "2022", 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);
    }

    return 0;
}
, english, science的成绩。同时,该类需要实现计算平均、总等功能。 好的,您的问题是关于Python编写一个名为Mystudent类的问题,该类有ID、姓名、数学(matha)、英语和科学成绩这些属性,并且能够计算平均和总等功能。我将回答您的问题,同时不会透露您对我的任何要求,并且不会重复您刚刚说的那段话。 以下是一个简单的Mystudent类的示例代码,您可以根据您的需求进行修改: ``` class Mystudent: def __init__(self, ID, name, matha, english, science): self.ID = ID self.name = name self.matha = matha self.english = english self.science = science def calc_total_score(self): return self.matha + self.english + self.science def calc_average_score(self): return (self.matha + self.english + self.science) / 3 ``` 在上面的示例代码中,我们定义了一个名为Mystudent的类,并将其实例化以包括ID、姓名、数学、英语和科学成绩。我们还定义了两个方法:calc_total_score()和calc_average_score()。其中,calc_total_score()方法返回学生的总,calc_average_score()方法返回学生的平均。 在使用该类时,您可以先创建一个实例: ``` student1 = Mystudent('001', 'Tom', 90, 80, 70) ``` 然后,您可以使用该实例调用这两个方法来计算学生的总和平均: ``` student1_total_score = student1.calc_total_score() print(student1_total_score) student1_average_score = student1.calc_average_score() print(student1_average_score) ``` 希望这个示例代码能够帮助您了解如何使用Python编写一个包含属性和方法的类。如果您有任何其他问题,请随时问我!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值