学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun(),它的功能是按分数的高低排列学生的记录,低分在前。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
define N 16
typedef struct
{ char mum[10);
int s;
}STREC;
int fun (STREC a[ ])
{
}
main ()
{
STREC s[N]={{“GA005”,88},{“GA003”,64},
{“CA002”,77},{“GA004”,89},{“GA001”,54},
{“GA007”,72},{“GA008”,72},{“GA006”,65},
{“GA015”,83},{“GA013”,95},{“GA012”,55},
{“GA014”,68},{“GA01l”,78},{“GA017”,53},
{“GA018”,92},{“GA016”,82}};
int i;
FILE *out;
fun(s);
printf(“The data after sorted :\n”);
for(i=0;i<N;i++)
{
if((i)%4==0)
/*每行输出4个学生记录*/
printf(“\n”);
printf(“%s %4d ”,s[i].num,s[i].s);
}
printf(“\n”);
ut=fopen(“out21.dat”,“w”);
for(i=0;i<N;i++)
{
if((i)%4==0&&i)
fprintf(out,“\n”);
fPrintf(out,“%4d”,s[i].s);
}
fprintf(out,“\n”);
fClose(out);
}
第1题
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
define N 16
typedef struct
{ char num[10];
int s;
}STREC;
int fun(STREC *a,STREC *b)
{
}
main ()
{
STREC s [N] = { { "GA005", 85 }, { "GA003", 76 },
{ "GA002", 69 }, { "GA004", 85 }, { "GA001", 91 },
{"GA007", 72}, {"GA008", 64}, {"GA006", 87},
{ "GA015", 85), ( "GA013", 91 }, { "GA012", 64 },
{ "GA014", 91 ), { "GA011", 66}, { "GA017", 64 },
{"GA018", 64 }, {"GA016", 72 } };
STREC h[N];
int i, n;
FILE *out;
n=fun(s,h);
printf("The %d highest score :\n",n);
for (i=0; i<n; i++)
printf("%s %4d\n ",h[i].num, h[i].s);
/*输出最高分学生的学号和成绩* /
printf("\n");
ut=fopen("out45.dat", "w");
fprintf(out, "%d\n",n);
for(i=0; i<n; i++)
fprintf(out, "%4d\n ",h[i].s);
fclose(out);
}
第2题
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
define N 12
typedef struct
{char num[10];
double S;
} STREC;
double fun(STREC *a,STREC *b,STREC *C,int *n,int *m)
{
}
main()
{
STREC s[N]={{“GA05”,65},{“GA03”,86},
{“GA02”,76},{“GA04”,95},{“GA01”,93},
{“GA07”,78},{“GA08”,68},{“GA06”,88},
{“GA09”,60},{“GAll”,54},{“GAl2”,56},
{“GAl0”,98}};
STREC h[N],l[N],t;
FILE *out;
int i,j,m,n;
double ave;
ave=fun(S,h,l,&n,&m);
printf("The %d student data which is higher than %7.3f:\n",n,ave);
for(i=0;i<n;i++)
printf("%s %4.lf\n",h[i].num,
h[i].s);
printf("\n");
printf("The %d Student data which iS lower than%7.3f:\n",m,ave);
for(i=0;i<m;i++)
printf("%s %4.1f\n",l[i].num, l[i].s);
printf("\n");
ut=fopen("out26.dat", "w");
fprintf(out, "%d\n %7.3f\n",n,ave);
for(i=0;i<n-1;i++)
for(j=i+1;i<n;j++)
if(h[i].s<h[j].s)
{t=h[i];h[i]=h[i];h[j]=t;}
/*分数从现到低排列*/
for(i=0;i<n; i++)
fprintf(out,“%4.1f\n",h[i].s);
fprintf(out,"%d\n %7.3f\n",m,ave);
for(i=0;i<m-1;i++)
for(j=i+1;i<m;j++)
if(l[i].s<l[j].s)
{t=l[i];l[i]=l[j];l[j]=t;}
/*分数从高到低排列*/
for(i=0;i<m;i++)
fprintf(out,"%4.1f\n",l[i].s);
fclose(out);
}
第3题
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的花括号中填入所编写的若干语句。
[试题源程序]
include<stdio.h>
define N 8
typedef struct
{
char num[10];
double s;
}STREC;
double fun(STREC *a, STREC *b, int *n)
{
}
void main()
{
STREC s[N]={{"GA05", 85},
{"GA03", 76}, {"GA02", 69}, {"GA04", 85},
{"GA01", 91}, {"GA07", 72}, {"GA08", 64},
{"GA06", 87}};
STREC h[N], t; FILE *out;
int i, j, n;
double ave;
ave=fun(s, h, &n);
printf("The %d student data which is lower than %7.3 f:\n", n, ave);
for(i=0; i<n; i++)
printf("%s %4.1f\n", h[i]. num, h[i].s);
printf("\n");
ut=fopen("out.dat", "W");
fprintf(out, "%d\n%7.3f\n", n, ave);
for(i=0; 2<n-1; i++)
for(j=i+1; j<n; j++)
if(h[i]. s>h[j].s)
{
t=h[i];
h[i]=h[j];
h[j]=t;
}
for(i=0; 2<n; i++)
fprintf(out, "%4.1f\n", h[i].s);
fclose(out);
}
第4题
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数flm的花括号中填入你编写的若干语句。
第5题
#include
#define N 16
typedef struct
{char num[10];
int s ;
} STREC;
int fun (STREC *a, STREC *b)
{int i,j=0,max=a[0].s;
for(i=0;i
if(max
for(i=0;i
if(【20】)b[j++]=a[i];
return j;
}
main ()
{STREC s[N]={{ "GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
{"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87},
{ "GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}
};
STREC h[N];
int i, n;FILE *out;
n=fun(s,h);
printf("The %d highest score :\n",n);
for (i=0; i
printf("%s M\n ",h[i].num,h[i].s);
printf("\n");
out=fopen("out15.dat", "w");
fprintf(out, "%d\n",n);
for(i=0; i
fprintf(out, "M\n ",h[i].s);
fclose(out);
}
第6题
第7题
注意:部分源程序存在文件PROGl.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的莅括号中填入你编写的若干语句。
第8题
例如,若学生的成绩是85.5,76,69.5,85,91,72,64.5, 87.5,则他的平均分应当是78.875。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
define N 8
typedef struct
{ char num [10];
double s[N];
double ave;
} STREC;
void fun()
{
}
main()
{
STREC s={"GA005",85.5,76,69.5,85,91, 72,64.5,87.5);
int i;
fun (&s);
printf("The %s' s student data:\n",s.num)/ /*输出学号*/
for(i=0;i<N; i++)
printf("%4.1f\n", s.s[i]);
/*输出各科成绩*/
printf("\nave=%7.3f\n",s.ave);
/*输出平均分*/
}
第9题
例如,学生的成绩是:85.5,76,69.5,85,91,72,64.5,87.5,则他的平均分应为78.875。注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fIm的花括号中填入你编写的若干语句。
第10题
请考生编写函数mmm(STUa[],STU*s)实现程序的要求,最后调用函数readwritedat()把结果输出到文件out.dat中。
例如:
KS01 87 60 88
KS09 97 59 99
KS11 67 67 60
则调用该函数后,输出
the top:KS01,87, 60, 88
include <stdio.h>
include <string.h>
define N 10
void readwritedat ();
typedef struct ss{
char num[10];
int s1, s2, s3;
}STU;
mmm(STU a[],STU *s)
{
}
main ( )
{
STU a[N]={
{ "01", 81, 93, 92},
{ "02", 89, 65, 91},
{ "03", 66, 55, 73},
{ "04", 87, 91, 99},
{ "05", 77, 65, 91},
{ "06", 90, 55, 73},
{ "07", 79, 65, 91},
{ "08", 61, 55, 73},
{ "09", 80, 93, 92},
{ "10", 71, 65, 91}
}m;
int i;
for (i=0; i<N; i++ )
printf ("No=%s Mark=%d\n",a[i] .num, a[i] .s1,a[i] .s2,a[i].s3);
mmm (a, &m);
printf("the highest: %s,%d\n",m.num,m.s1+m.s2+m.s3);
readwritedat ( );
}
void readwritedat ( )
{
FILE *rf, *wf;
STU a[N] ,m;
int i;
rf=fopen ( "in. dat", "r" );
wf=fopen ( "out. dar", "w" );
for (i=0; i<10; i++)
fscanf (rf, "%s%d%d%d", a [i] .hum, &a[i] .s1, &a[i] .s2, &a [i] .s3);
mmm(a, &m);
fprintf(wf,"the top: %s,%d,%d,%d\n",m.num,m.s1,m.s2,m.s3);
fclose (rf);
fclose (wf);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!