当前位置:网站首页>Exercise 9-6 statistics of student scores by grade (20 points)
Exercise 9-6 statistics of student scores by grade (20 points)
2022-06-11 22:25:00 【Xiaoyan y】
According to the students' grades, the students' grades should be set , And count the number of failed simple function .
Function interface definition :
int set_grade( struct student *p, int n );
among p Is the pointer to the structure array of student information , The structure is defined as :
struct student{
int num;
char name[20];
int score;
char grade;
};
n Is the number of array elements . Student number num、 full name name And achievements score It's all stored .set_grade The function needs to be based on the student's grade score Set its level grade. Level setting :85-100 by A,70-84 by B,60-69 by C,0-59 by D. meanwhile ,set_grade You also need to return the number of people who failed .
Sample referee test procedure :
#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;
}/* Your code will be embedded here */
sample input :
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
sample output :
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;
}
边栏推荐
- Nmap performs analysis of all network segment IP survivals in host detection
- 习题11-2 查找星期 (15 分)
- 向线程池提交任务
- 使用VBScript读取网络的日志数据进行处理
- Custom implementation offsetof
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.4
- Three methods of quick sorting
- 启牛推荐开通的证券账户安全吗?靠谱吗
- 【Uniapp 原生插件】商米钱箱插件
- One question of the day - delete duplicates of the ordered array
猜你喜欢

win11怎么看电脑显卡信息

学1个月爬虫就月赚6000?别被骗了,老师傅告诉你爬虫的真实情况

leetcode 257. Binary tree paths all paths to a binary tree (simple)

什么是死锁?(把死锁给大家讲明白,知道是什么,为什么用,怎么用)

Tkinter study notes (II)

Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)

移动端——swipe特效之图片时间轴

Analysis of the implementation principle of an open source markdown to rich text editor

Daily question - Roman numeral to integer

Tkinter学习笔记(三)
随机推荐
机器学习之线性回归简单实例
Implementation stack and queue
点云读写(二):读写txt点云(空格分隔 | 逗号分隔)
利用SecureCRTPortable脚本功能完成网络设备的数据读取
A simple example of linear regression in machine learning
STM32开发笔记113:ADS1258驱动设计——读取温度值
69. square root of X
Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.3
Dynamics 365 选项集操作
Tkinter学习笔记(四)
3.3 测试模块的命名规则
Brief introduction to integrity
How to view computer graphics card information in win11
Maze problem in C language
MATLAB点云处理(二十五):点云生成 DEM(pc2dem)
Leetcode - day 2
【Uniapp 原生插件】商米钱箱插件
3.2 naming rules of test classes
习题10-1 判断满足条件的三位数 (15 分)
超标量处理器设计 姚永斌 第2章 Cache --2.3 小节摘录