下列程序的功能是:已知学生的记录由学号和学习成绩构成,N名学生的数据已存入数组a中,找出成绩最高的学生的记录(假定最高成绩记录是唯一的),通过形参返回。请编写函数mmm(STU a[],STU*s)实现程序要求,最后调用函数reawriteDAT()把结果输出到文件out.dat中。 例如:KS01 87 KS09 67 KS11 97 则调用该函数后将输出: The lowest:KS09,67 注意:部分源程序已给出。 请勿改动主函数main()和函数readwriteDAT()的内容。 [试题源程序] #include<Stdio.h> #include<string.h> #include<conio.h> #defime N 10 void readwriteDat(); typedef struct ss
char num[10];int s; STU; void mmm(STU a[],STU*s)
msin()
STU a[N]="A01",81,"A02",89),"A03",81),"A01",66),"A04",87),"A05",77),"A07",79),"A08",61),"A09",80,"A10",71,),m; int i; System("cls"); printf("***** The original data ***** \n"); for(i=0;i<N;i++) printf("No=%s Mark=%d\n",a[i].num,a[i].s); mmm(a,&m); printf("***** THE RESULT*****\n"); printf("The highest:%s,%d\n",m.num,m.s); readwriteDat();
void readwriteDat()
FILE *rf,*wf; STU a[N],m; int i; rf=fopen("in.dat","r"); wf=fopen("out.dat","w"); for(i=0;i<10;i++)fscanf(rf,"%s%d",a[i].num,&a[i].s); mmm(a,&m); fprintf(wf,"The lowest:%s,%d\n",m.num,m.s); fclose(rf); fclose(wf);
【参考答案】
void mmm(STU a[],STU *s) { int i; s->s=a[0].s......