zoukankan      html  css  js  c++  java
  • 第九周作业

    这个作业属于那个课程 C语言程序设计II
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass4-2018/homework/3126
    我在这个课程的目标是 学会如何使用结构
    这个作业在那个具体方面帮助我实现目标 结构在题目中的应用
    参考文献 C语言程序设计II

    按等级统计学生成绩

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

    函数接口定义:

    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);
        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
    ", count);
       printf("The grades:
    "); 
       for(i = 0; i < n; i++)
           printf("%d %s %c
    ", 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 s = 0;
        for(int i = 0;i<n;i++,p++)
               {
            if(p->score<60)
               {
                p->grade = 'D';
                s++;
               }
            else if((p->score<70)&&(p->score>=60))
                       {
                p->grade = 'C';
               }
            else if((p->score<85)&&(p->score>=70))
                      {
                p->grade = 'B';
              }
            else
               {
                p->grade = 'A';
               }
        }
        return s;
    }

    设计思路:

    本题调试过程中碰到的问题及解决方法:

    判断语句中p用错了,不能直接用P>或者其他的符号来判断该函数的区域,这个地方错误

    正确截图:

     学习进度条

    周/日期 这周所花的时间 代码行数 学到的知识点简介 目前比较迷惑大问题
    9周 5小时 45 结构体的构造 题目:一帮一,考试座位号

    学习感悟

    本周我对作业感觉非常,就只做出来了一题,还是问了别人又看了书才会的,自己的能力还是太弱了,希望自己多刷题,弥补自己的缺失

    结对编程:

    本周的结对编程让我意识到了结对编程的重要性,他可以扬长避短,让自己更加全面。

  • 相关阅读:
    log4j2 配置详解
    MANIFEST.MF文件详解
    assembly.xml
    firewall 和 iptables 常用命令
    Spring boot 使用 configuration 获取的属性为 null
    使用 maven-assembly-plugin 打包项目
    使用 Maven 插件将 class(字节码文件),resource(资源文件),lib(依赖的jar包)分开打包
    HttpClient 传输文件的两种方式
    IDEA中读取 resource目录下文件
    3.2、Android Studio在物理设备中运行APP
  • 原文地址:https://www.cnblogs.com/tb-0706/p/10774833.html
Copyright © 2011-2022 走看看