返回的不及格人数不对。
题目主要:
实现接口 int set_grade( struct student *p, int n );
主程序
#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;
}
/* 你的代码将被嵌在这里 */
功能函数:
int set_grade( struct student *p, int n ){
int count=0;
while((*p).num!=0){
if((*p).score<=59&&(*p).score>=0){
(*p).grade='D';
count++;
}else if((*p).score>=60&&(*p).score<=69){
(*p).grade='C';
}else if((*p).score>=70&&(*p).score<=84){
(*p).grade='B';
}else if((*p).score>=85&&(*p).score<=100){
(*p).grade='A';
}
p++;
}
return count;
}
测试用例:
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
实际输出:
The count for failed (<60): 2
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