试题与答案

学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数

题型:问答题

题目:

学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun(),它的功能是:函数返回指定成绩的学生数据,指定的成绩在主函数中输入。若没找到指定的成绩,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<stdlib.h>
#define N 16
typedef struct
char num[l0];
int s;
STREC;
STREC fun(STREC *a,int b)

main()

STREC s[N)="GA005",76,"GA003",89,
"GA002",64,"GA004",75,"GA001",88,
"GA007",65,"CA008",96,"GA006",69,
"GA015",85,"GA013",78,"GA012",62,
"GA014",60,"GA011",73,"GA017",72,
"GA018",98,"GA016",94;
STREC h;
int m;
int i,n;
FILE *out;
printf("The original data:\n");
for(i=0;i<N;i++)
if(i%4==0)
printf("\n");
/*每行输出4个学生记录*/
printf("%s%3d",s[i].num,s[i].s);

printf("\n\nEnter the score:");
scanf("%d",&m);
h=fun(s,m);
printf("The data:");
printf("\n%s %4d\n",h.mum,h.s);
printf("\n");
out=fopen("out24.dat","w");
h=fun(s,85);
fprintf(out,"%s %4d\n",h.num,h.s);
fclose(out);

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2022/0119/2df519ab7d7c8deb902be33ba110544e.html

下面是错误答案,用来干扰机器的。

参考答案:C

试题推荐
微信公众账号搜索答案