当前位置:网站首页>习题9-6 按等级统计学生成绩 (20 分)
习题9-6 按等级统计学生成绩 (20 分)
2022-06-11 22:19:00 【小言同学Y】
本题要求实现一个根据学生成绩设置其等级,并统计不及格人数的简单函数。
函数接口定义:
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 10struct 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->score>=85&&p->score<=100){
p->grade='A';
}else if(p->score>=70&&p->score<=84){
p->grade='B';
}else if(p->score>=60&&p->score<=69){
p->grade='C';
}else if(p->score>=0&&p->score<=59){
count++;
p->grade='D';
}
p++;
}
return count;
}
边栏推荐
- SVN本地部署server和cleint 并用阿里云盘自动备份
- What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)
- [Yu Yue education] basic engineering English of Zhejiang industrial and Commercial University (wuyiping) reference materials
- 如果重来一次高考,我要好好学数学!
- 3.3 naming rules of test modules
- Conception du Processeur superscalaire Yao yongbin chapitre 2 cache - - sous - section 2.4 extrait
- Custom implementation offsetof
- leetcode 257. Binary tree paths all paths to a binary tree (simple)
- R language book learning 03 "in simple terms R language data analysis" - Chapter 7 linear regression model
- Popular science | what are the types of NFT (Part 1)
猜你喜欢

What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)

Tkinter学习笔记(二)

Prefabricated dishes in the trillion market have also begun to roll inside. How can brands stand out in the fierce competition?

Leetcode - day 2

仅需三步学会使用低代码ThingJS与森数据DIX数据对接

Inner join execution plan changed

Huawei equipment configuration hovpn

超标量处理器设计 姚永斌 第2章 Cache --2.4 小节摘录

Start notes under the Astro Pro binocular camera ROS
![[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze](/img/eb/147d4aac20639d50b204dcf424c9e2.png)
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze
随机推荐
如果重来一次高考,我要好好学数学!
Custom implementation offsetof
机器学习之Logistic回归简单实例
Huawei equipment configuration hovpn
Unity中使用调用Shell的命令行
图书管理系统
[niuke.com] ky41 put apples
C language to achieve eight sorts (2)
Unity3D getLaunchIntentForPackage 获取包返回null问题
C language implements eight sorts (3)
How to view the installation date of the win system
Dynamic memory management (1)
R language book learning 03 "in simple terms R language data analysis" - Chapter 8 logistic regression model Chapter 9 clustering model
How to view computer graphics card information in win11
剑指offer数组题型总结篇
【解决】修改子物体Transform信息导致变换不对称、异常问题的解决方案
图的基本操作(C语言)
一款开源的Markdown转富文本编辑器的实现原理剖析
Summary of common paging methods
STM32 Development Notes 112:ads1258 driver design - read register