第9周作业

这个作业属于那个课程C语言程序设计II
这个作业要求在哪里https://edu.cnblogs.com/campus/zswxy/MS/homework/3129
我在这个课程的目标是了解并熟练掌握结构体的使用方法,结构变量的定义和初始化。
这个作业在那个具体方面帮助我实现目标熟悉结构体的使用
参考文献c语言程序设计第三版

 

 

 

 

6-1 按等级统计学生成绩 (20 分)

本题要求实现一个根据学生成绩设置其等级,并统计不及格人数的简单函数。

函数接口定义:

int set_grade( struct student *p, int n );

其中p是指向学生信息的结构体数组的指针,该结构体的定义为:

struct student{
    int num;
    char name[20];
    int score;
    char grade;
};

n是数组元素个数。学号num、姓名name和成绩score均是已经存储好的。set_grade函数需要根据学生的成绩score设置其等级grade。等级设置:85-100为A,70-84为B,60-69为C,0-59为D。同时,set_grade还需要返回不及格的人数。

裁判测试程序样例:

#include <stdio.h>
#define MAXN 10

struct student{
    int num;
    char name[20];
    int score;
    char grade;
};

int set_grade( struct student *p, int n );

int main()
{   struct student stu[MAXN], *ptr;
    int n, i, count;

    ptr = stu;
    scanf("%d\n", &n);
    for(i = 0; i < n; i++){
       scanf("%d%s%d", &stu[i].num, stu[i].name, &stu[i].score);
    } 
   count = set_grade(ptr, n);
   printf("The count for failed (<60): %d\n", count);
   printf("The grades:\n"); 
   for(i = 0; i < n; i++)
       printf("%d %s %c\n", stu[i].num, stu[i].name, stu[i].grade);
    return 0;
}

/* 你的代码将被嵌在这里 */

输入样例:

10
31001 annie 85
31002 bonny 75
31003 carol 70
31004 dan 84
31005 susan 90
31006 paul 69
31007 pam 60
31008 apple 50
31009 nancy 100
31010 bob 78

输出样例:

The count for failed (<60): 1
The grades:
31001 annie A
31002 bonny B
31003 carol B
31004 dan B
31005 susan A
31006 paul C
31007 pam C
31008 apple D
31009 nancy A
31010 bob B

实验代码:

int set_grade( struct student *p, int n )
{
    int count=0,i;
    for(i=0;i<n;i++){
        if((p+i)->score<60){
            count++;
            (p+i)->grade='D';
        }
        if((p+i)->score>=60&&(p+i)->score<=69)
            (p+i)->grade='C';
        if((p+i)->score>=70&&(p+i)->score<=84)
            (p+i)->grade='B';
        if((p+i)->score>=85&&(p+i)->score<=100)
            (p+i)->grade='A';
    } 
    return count;
} 

周/日期这周所花时间代码行数目前比较迷茫的问题学到的知识点
第九周/4月26日俩天17结构变量的使用学习了结构体的使用

转载于:https://www.cnblogs.com/a1611040777/p/10776123.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值