任务描述
学生成绩统计
从键盘输入一个班(全班最多不超过30人)学生的某门课的成绩,当输入成绩为负值时,输入结束,分别实现下列功能:
(1) 统计不及格人数并打印不及格学生名单。
(2) 统计成绩在全班平均分及平均分之上的学生人数,并打印这些学生的名单;
(3) 统计各分数段的学生人数及所占的百分比。
本关任务要求在前一关的基础上,编写函数,实现功能(2)。
编程要求
在前一关的基础上,增加函数GetFail,统计不及格人数并打印不及格学生名单。
测试说明
我会对你编写的代码进行测试:
第一关:输入学生信息后,以及输出的格式为:
第二关:统计不及格人数并打印不及格学生名单,输出的内容为:
1 #include <stdio.h> 2 #define ARR_SIZE 30 3 /************Begin***********/ 4 //′?′|?óé?ê?è??§éúD??¢μ?oˉêyéù?÷ 5 6 7 /************End*************/ 8 int tjStudent(int num[ARR_SIZE],float score[ARR_SIZE]){ 9 10 int n=0; 11 for(int i=1;i<=ARR_SIZE;i++){ 12 // printf("请输入第%d位学生的学号and成绩",i); 13 scanf("%d %f",&num[i],&score[i]); 14 if(num[i]<=0 ||score[i]<=0){ 15 break; 16 }else{ 17 18 n++; 19 } 20 21 } 22 return n; 23 24 } 25 int getFailStudent(int num[ARR_SIZE],float score[ARR_SIZE]){ 26 int n=0; 27 printf("Fail:\n"); 28 printf("number--score\n"); 29 for(int i=1;i<11;i++){ 30 if(score[i] <60){ 31 32 printf("%d------%.0f\n",num[i],score[i]); 33 n++; 34 } 35 //TODO 36 } 37 return n; 38 39 } 40 int main(void) 41 { 42 int n=0; 43 float score[ARR_SIZE]; 44 int num[ARR_SIZE]; 45 printf("Please enter num and score until score<0:\n"); 46 47 n=tjStudent(num,score); 48 49 /************Begin***********/ 50 //′?′|?óé?oˉêyμ÷ó? 51 52 /************End*************/ 53 printf("Total students:%d\n", n); 54 55 n=getFailStudent(num,score); 56 printf("Fail students = %d\n", n); 57 return 0; 58 } 59 60 61 //oˉêy1|?ü£o′ó?ü?ìê?è?ò???°à?§éú?3????μ?3é?¨?°???§o? 62 //μ±ê?è?3é?¨?a?o?μê±£?ê?è??áê?£?oˉêy·μ???§éú×üêy 63 /************Begin***********/ 64 65 66 /************End*************/