下列给定程序中,函数fun()的功能是:对N名学生的学习成绩,按从低到高的顺序找出前m(m≤10)名学生来,并将这些学生数据存放在一个动态分配的连续存储区中,此存储区的首地址作为函数值返回。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <string.h>
include <stdio.h>
include <alloc.h>
define N 10
typedef struct SS
{
char num[10];
int s;
}STU;
STU *fun(STU a[],int m)
{
STU b[N],*t;
int i, j,k;
/*************found*************/
*t=calloc(m,sizeof(STU));
for(i=0;i<N;i++)
b[i]=a[i];
for(k=0;k<m;k++)
{
/*************found*************/
for(i=j=0;i<N;j++)
if(b[i].s<b[j],s)
j=i;
/*************found*************/
t[k].s=b[j].s;
b[j].s=100;
}
return t;
}
outresult(STU a[],FILE *pf)
{
int i;
for(i=0;i<N;i++)
fprintf(pf,"NO=%S Mark=%d\n",
a[i].num,a[i].S);
fprintf(pf,"\n\n");
}
main()
{
STU a[N]={{“A01”,77},{“A02”,85},
{“A03”,96},{“A04”,65},{“A05”,75},
{“A06”,96},{“A07”,76},{“A08”,63},
{“A09”,69},{“A10”,78}};
STU *porder;
int i,m;
clrscr();
printf(“*****THE RESULT*****\n”);
outresult(a,stdout);
printf(“\nGive the number of the students who have lower score:”);
scanf(“%d”,&m);
while(m>10)
{
printf(“\nGive the number of the students who have lower score:”);
scanf(“%d”,&m);
}
porder=fun(a,m);
printf(“*****THE RESULT*****\n”);
printf(“The low:\n”);
for(i=0;i<m;i++)
printf(“%s %d\n”,porder[i].num,
porder[i].s);
free(porder);
}
第1题
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <string.h>
include <stdio.h>
include <alloc.h>
define N 10
typedef struct SS
{
char num[10];
int s;
}STU;
STU *fun(STU a[],int m)
{
STU b[N],*t;
int i, j,k;
/*************found*************/
*t=calloc(m,sizeof(STU));
for(i=0;i<N;i++)
b[i]=a[i];
for(k=0;k<m;k++)
{
/*************found*************/
for(i=j=0;i<N;j++)
if(b[i].s<b[j],s)
j=i;
/*************found*************/
t[k].s=b[j].s;
b[j].s=100;
}
return t;
}
outresult(STU a[],FILE *pf)
{
int i;
for(i=0;i<N;i++)
fprintf(pf,"NO=%S Mark=%d\n",
a[i].num,a[i].S);
fprintf(pf,"\n\n");
}
main()
{
STU a[N]={{“A01”,77},{“A02”,85},
{“A03”,96},{“A04”,65},{“A05”,75},
{“A06”,96},{“A07”,76},{“A08”,63},
{“A09”,69},{“A10”,78}};
STU *porder;
int i,m;
clrscr();
printf(“*****THE RESULT*****\n”);
outresult(a,stdout);
printf(“\nGive the number of the students who have lower score:”);
scanf(“%d”,&m);
while(m>10)
{
printf(“\nGive the number of the students who have lower score:”);
scanf(“%d”,&m);
}
porder=fun(a,m);
printf(“*****THE RESULT*****\n”);
printf(“The low:\n”);
for(i=0;i<m;i++)
printf(“%s %d\n”,porder[i].num,
porder[i].s);
free(porder);
}
第2题
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
include <conio.h>
include <string.h>
include <stdio.h>
include <alloc.h>
define N 10
typedef struct ss
{char num[10];
int s;
} STU;
STU *fun{STU a[], int m)
{ STU b[N] ,*t;
int i, j,k;
/*************found**************/
*t=calloc (m, slzeof (STU));
for(i=0;i<N;i++) b[i]=a[i];
for(k=0; k<m; k++)
{ for (i=j=0;i<N;i++)
if (b[i].s>b[j].s) j=i;
/*************found**************/
t[k].num=b [j].num;
t[k].s=b[j] s;
b[j].s=0;
}
return t;
}
outresult(STU a[],FILE *pf)
{ int i;
for (i=0; i<N; i++)
fprintf(pf, "No=%s Mark-%d\n ",
a [i] .num, a[i].s);
fprintf(pf, "\n\n ");
}
main ( )
{ STU a[N]={{ "A01 ",81},{ "A02 ",89},
{ "A03 ",66},{ "A04 ",87},{ "A05 ",77},
{ "A06 ",90},{ "A07 ",79},{ "A08 ",61},
{ "A09 ",80},{ "Al0 ",71}};
STU *pOrder;
int i, m;
clrscr ();
printf ("*****THE RESULT***** \n");
outresult (a, stdout);
printf ("\nGive the number of the students
who have better score: ");
scanf ("%d", &m);
while (m>10)
{ printf("lnGive the number of the
students who have better score: ");
scanf ("%d", %m);
pOrder=fun (a,m);
printf("***** THE RESULT*****kn");
printf("The top :\n");
for (i=0; i<m; i++)
printf("%s %d\n",pOrder[i].num,
p0rder [i]. s);
free (pOrder);
}
第3题
请改正函数fun中指定部位的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
第4题
注意:部分源程序存在文件PROGl.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的莅括号中填入你编写的若干语句。
第5题
1.请大家将写好的代码截图上传,以添加图片的方式哦,不要以上传文件的形式~ 2.这个例子可以很好的帮助大家巩固有关结构体、函数调用、输入输出、模块化思想方面的知识,对于后续理解课程代码有很大的帮助作用,希望大家认真思考完成哦^_^ 3.作业提交后需要大家完成作业互评,评价其他5位同学的代码,未参与互评者仅能得到自己所得评价平均分的50%,未完成互评者仅能得到自己所得评价平均分的80%。此外,大家也可学习其它同学的设计思路,了解其他同学的代码编写习惯、编写水平,希望大家积极参与! 4.注意截止时间。 有8个学生的数组存放于结构数组a中,每个学生记录由学号num和成绩score组成,编写程序,使其实现: (1)main中输入8个学生的学号及成绩 (2)设计函数fun(),用于统计8个学生的平均成绩aver, (3)main中输出平均值aver、以及成绩大于等于平均值的每位学生记录(包含学号、成绩) #include <stdio.h> #define N 8 struct stu { int num; float score; }; //fun函数定义 int main( ) { return 0; }
第6题
下列给定程序中,函数fun()的功能是:从n个学生的成绩中统计出高于平均分的学生人数,人数由函数值返回,平均分存放在形参aver所指的存储单元中。例如输入8名学生的成绩:
85 65.5 69 95.5 87 55 62.5 75
则高于平均分的学生人数为4(平均分为74.312500)。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <conio.h>
define N 20
int fun(float *S,int n,float *aver)
{
/*************found*************/
int ave,t=0;
int count=0,k,i;
for(k=0;k<n;k++)
t+=s[k];
ave=t/n;
for(i=0;i<n;i++)
/*************found***************/
if(s[i]<ave)
count++;
/*************found*************/
aver=ave;
return count;
}
main()
{
float S[30],aver;
int m,i;
clrscr();
printf("\nPlease enter m:");
scanf("%d",&m);
printf("\nPlease enter%d mark:\n",m);
for(i=0;i<m;i++)
scanf("%f",s+i);
printf("\nThe number of students:%d\n",
fun(S,m,&aver));
printf(“AVe=%f\n”,aver);
}
第7题
学生的记录由学号和成绩组成,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);
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!