N7FAA52318 2022-01-08 03:07 采纳率: 62.5%
浏览 715
已结题

C语言- 评定等级成绩

######学生结构体定义如下:

其中每一项的含义如以上代码中的注释所述。本题要求实现一个函数,按照以下规则计算学生的总评等级成绩:

(1)共有C语言 英语 数学三门成绩,每门成绩为百分制。单科成绩不低于60分为通过;

(2)总评等级成绩有5档,分数为5 4 3 2 1,分别表示优秀、良好、中等、及格、未通过;

(3)C语言、英语、数学成绩中,有任何一门未通过(即低于60分),则总评成绩为“未通过”;

(4)若三门单科成绩均通过,则根据三科平均成绩评定:

C语言成绩低于90分的,不得评定为优秀,即无论平均分是多少,最高评为良好;
平均成绩超过90分的,评定为优秀(5分),但C语言成绩不符合要求的只能评为良好;
平均成绩超过80分且不超过90分的,评定为良好(4分);
平均成绩超过70分且不超过80分的,评定为中等(3分);
平均成绩超过60分且不超过70分的,评定为及格(2分);
平均成绩不超过60分的,评定为未通过(1分)。
提示:仔细阅读评分规则,注意与平时常见规则的不同,例如平均分为80分的,等级是“中等”而不是“良好”。

函数接口定义:
int calScore(struct Student *stu);
其中stu是传入的参数,指向要评定等级成绩的学生结构体变量。函数返回值为int型。

函数要做到:

根据规则计算该学生的等级成绩,并写入该学生结构体的grade成员(数据项)中
若该学生总评成绩通过(2分至5分),则函数返回1;若总评成绩未通过(1分),则函数返回0
裁判测试程序样例:
此裁判测试程序仅为示例,实际的测试程序可能不同。

输入样例:
对于样例裁判程序的输入格式:(实际的输入格式可能随裁判程序的不同而变化)

4
zhangsan 1001 95 87 90
lisi 1002 79 80 81
wangwu 1003 85 99 99
zhaoliu 1004 58 90 92
结尾无空行
输出样例:
对于样例裁判程序的输出格式:(实际的输出格式可能随裁判程序的不同而变化)

(1001, zhangsan) : 5(1)
(1002, lisi) : 3(1)
(1003, wangwu) : 4(1)
(1004, zhaoliu) : 1(0)
结尾无空行

问题相关代码,请勿粘贴截图
我的代码运行编译错误
我的解答思路和尝试过的方法
#include <stdio.h>
struct Student{
    char name[50];  //姓名
    int sid;    //学号
    int C;   //C语言成绩
    int English;   //英语成绩
    int math;   //数学成绩
    int grade;   //总评等级成绩
};
int calScore(struct Student *stu);
int main(){
    int n;
    scanf("%d", &n);
    struct Student stu;
    int pass;
    for(int i=0; i<n; i++){
        scanf("%s%d%d%d%d", stu.name, &stu.sid, &stu.C,
              &stu.English, &stu.math);
        pass = calScore(&stu);
        printf("(%d, %s) : %d(%d)\n", stu.sid, stu.name, stu.grade, pass);
    }
    return 0;
}
int calScore(struct Student *stu)
{
    int ave;
    ave=( (*stu).C + (*stu).English + (*stu).math)/3;
    if((*stu).C<60||(*stu).English<60||(*stu).math<60||ave<60)
    {
        (*stu).grade=5;
        return 0;
    }   
    else if((*stu).C<90&&ave>90)
    {
            (*stu).grade=2;
    }
    switch(ave)
    {
        case (ave>90):(*stu).grade=1;break;
        case (ave>80&&ave<=90):(*stu).grade=2;break;
        case (ave>70&&ave<=80):(*stu).grade=3;break;
        case (ave>60&&ave<=70):(*stu).grade=4;break;
    }
    return 1;
    }
}
请指正错误地点和原因,万分感谢!
  • 写回答

1条回答 默认 最新

  • _GX_ 2022-01-08 08:42
    关注
    #include <stdio.h>
    
    struct Student
    {
        char name[50]; //姓名
        int sid;       //学号
        int C;         //C语言成绩
        int English;   //英语成绩
        int math;      //数学成绩
        int grade;     //总评等级成绩
    };
    
    int calScore(struct Student *stu);
    
    int main()
    {
        int n;
        scanf("%d", &n);
        struct Student stu;
        int pass;
        for (int i = 0; i < n; i++)
        {
            scanf("%s%d%d%d%d", stu.name, &stu.sid, &stu.C,
                  &stu.English, &stu.math);
            pass = calScore(&stu);
            printf("(%d, %s) : %d(%d)\n", stu.sid, stu.name, stu.grade, pass);
        }
        return 0;
    }
    
    int calScore(struct Student *stu)
    {
        float ave = (stu->C + stu->English + stu->math) / 3.0f;
        if (ave > 90)
            stu->grade = 5;
        else if (ave > 80)
            stu->grade = 4;
        else if (ave > 70)
            stu->grade = 3;
        else if (ave > 60)
            stu->grade = 2;
        else
            stu->grade = 1;
        if (stu->C < 90 && stu->grade == 5)
            stu->grade = 4;
        return stu->grade >= 2;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月17日
  • 已采纳回答 1月9日
  • 创建了问题 1月8日

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统