1、第八章 以下叙述中正确的是() 若有以下语句 typedefstruct S {int g; char h;}T; A.可用T定义结构体变量 B.T是struct S类型的变量 C.可用S定义结构体变量 D.S是struct类型的变量 当定义一个结构体变量时,系统分配给它的内存是( )。 A.结构体中最后一个成员所需内存量 B.成员中占内存量最大的容量 C.结构体中第一个成员所需内存量 D.各成员所需内存量的总和 若有以下定义: struct link { int data; struct link *next; }a,b,c,*p,*q
2、 且变量a和b之间已有如下图所示的链表结构,若指针p指向a,指针q指向c。 则能把c插入到a和b之间形成新的链表的语句是( ) A.p->next=&c;q->next=p->next; B.p.next=q;q.next=p.next; C.p->next=q; q->next=&b; D.a.next=c; c.next=b; /*N名学生的成绩已在主函数中放入一个带头节点的链表结构中,h指向链表的头节点。 请编写函数fun,它的功能是:求出平均分,由函数值返回。 例如,若学生的成绩是85,76,69,91,72,64,87,则平均分应当是78.625。
3、
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:*/
#include
4、/
}
STREC *creat(double *s) /*创建链表*/
{
STREC *h,*p,*q;
int i=0;
h=p=( STREC*)malloc(sizeof(STREC));
p->s=0;
while(i
5、 p=h->next; printf("head "); do {printf("->%4.1f ",p->s); p=p->next; /*输出各成绩*/ } while(p!=NULL); printf("\n\n"); } void main() { FILE *wf; double s[N]={85,76,69,85,91,72,64,87},ave; STREC *h; h=creat(s); outlist(h); ave=fun(h); printf("ave=%
6、6.3f\n ",ave); /******************************/ wf=fopen("debug\\out25.dat","w"); fprintf(wf,"%6.3f\n",ave); fclose(wf); /*****************************/ } 【参考代码】 double av=0.0; STREC *p=h->next; /*p直接指向"头节点"的下一个节点,即第一个成绩*/ while(p!=NULL) {av=av+p->s; /*求总分数*/
7、 p=p->next;
}
return av/N; /*返回平均值*/
/*学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,该函数的功能是:
把高于等于平均分的学生数据放在b所指的数组中,高于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序: */
#include
8、r num[10]; double s; } STREC; double fun (STREC *a,STREC *b, int *n) { /*************Begin************/ /*************End*************/ } void main() { FILE *wf; STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85}, {"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87}, {
9、"GA09",60},{"GA11",79},{"GA12",73},{"GA10",90}};
STREC h[N],t;
int i,j,n;
double ave;
ave=fun(s,h,&n);
printf("The %d student data which is higher than %7.3f:\n",n,ave);
for(i=0; i 10、or(j=i+1;j 11、/
}
【参考代码】
int i;
double av=0.0;
*n=0;
for(i=0;i 12、返回平均分*/
/*学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,
它的功能是:把指定分数范围内的学生数据放在b所指的数组中,分数范围内的学生人数由函数值返回。
例如,输入的分数是60和69,则应当把分数在60到69的学生数据进行输出,包含60分和69分的学生数据。
主函数中把60放在low中,把69放在heigh中。注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序: */
#include 13、ypedef struct
{ char num[10];
int s ;
}STREC;
int fun (STREC *a, STREC *b, int l, int h )
{
/************Begin*************/
/************End************/
}
void main ()
{
FILE *wf;
STREC s[N]={{ "GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
{"GA001",96},{"GA 14、007",72},{"GA008",64},{"GA006",87},
{"GA015",85},{"GA013",94},{"GA012",64},{"GA014",91},
{"GA011",90},{"GA017",64},{"GA018",64},{"GA016",72}};
STREC h[N],tt;
int i, j,n, low, heigh, t;
printf("Enter 2 integer number low & heigh: ");
scanf("%d%d",&low,&heigh);
if(heigh 15、 {t=heigh;heigh=low; low=t;}
n=fun(s,h,low, heigh);
printf("The student 's data between %d--%d:\n ",low, heigh);
for(i=0;i 16、 /*分数在80~98之间的学生记录按分数从低到高排列*/
for(j=i+1;j 17、 int i,j=0;
for(i=0;i 18、5,则他的平均分应当是78.875。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序: */
#include 19、
void main()
{
FILE *wf;
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 20、/
/******************************/
wf=fopen("debug\\out24.dat","w");
fprintf(wf,"ave=%7.3f\n", s.ave);
fclose(wf);
/*****************************/
}
【参考代码】
int i;
p->ave=0.0;
for(i=0;i 21、习成绩构成,N名学生的数据已存入a结构体数组中。请编写函数fun,
该函数的功能是:找出成绩最低的学生记录,通过形参返回主函数(规定只有一个最低分)。已给出函数的首部,请完成该函数。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:*/
#include 22、 a[], STU *s)
{
/***********Begin**************/
/***********End**************/
}
void main()
{
FILE *wf;
STU a[N]={{ "A01",81},{ "A02",89},{ "A03",66},{ "A04",87},{ "A05",77},
{ "A06",90},{ "A07",79},{ "A08",61},{ "A09",80},{ "A10",71}},m;
int i;
printf("*****The origi 23、nal data*****\n");
for(i=0;i 24、e(wf);
/*****************************/
}
【参考代码】
int i;
*s=a[0]; /*先认为第1个值最小*/
for(i=0;i 25、生的人数。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:*/
#include 26、[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},{"GA01",91},
{"GA07",72},{"GA08",64}, {"GA06",87},{"GA015",85},{"GA013",91},
{"GA012",64},{"GA014",91},{"GA011",91},{"GA017",64},{"GA018",64},{"GA016",72}};
STREC h[N];
int i,n;
FILE *out;
n=fun(s,h);
printf("The %d lo 27、west score:\n",n);
for(i=0;i 28、/
}
【参考代码】
int i,j=0,n=0,min;
min=a[0].s;
for(i=0;i 29、数fun,它的功能是:
把低于平均分的学生数据放在b所指的数组中,低于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。试题程序: */
#include 30、
/************End***************/
}
void main()
{
FILE *wf;
STREC s[N]={{ "GA05 ",85},{ "GA03 ",76},{ "GA02 ",69},{ "GA04 ",85},
{ "GA01 ",91},{ "GA07 ",72},{ "GA08 ",64},{ "GA06 ",87}};
STREC h[N];
int i,n;
double ave;
ave=fun(s,h,&n);
printf("The %d student data 31、which is lower than %7.3f:\n ", n,ave);
for(i=0;i 32、 %4.1f\n",h[i].num,h[i].s);
fclose(wf);
/*****************************/
}
【参考代码】
int i,j=0;
double av=0.0;
for(i=0;i 33、平均值的学生人数*/
return av;
/*返回平均值*/
/*学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:
把分数最高的学生数据放在b所指的数组中,注意:分数最高的学生可能不止一个,函数返回分数最高的学生的人数。
注意: 部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
给定源程序: */
#include 34、ar num[10];
int s;
} STREC;
int fun( STREC *a, STREC *b )
{
/**************Begin*************/
/*************End***************/
}
int main()
{ STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},
{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
{"G 35、A015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",77},{"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 36、pen("debug\\out.dat","w");
for(i=0;i 37、 38、91},{"GA007",72},{"GA008",64},{"GA006",87},
{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};
int i;
fun(s);
printf("The data after sorted :\n");
for (i=0; i 39、/
wf=fopen("debug\\out23.dat","w");
for (i=0; i 40、 {t=a[j];a[j]=a[j+1];a[j+1]=t;}
/*学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,
它的功能是:把分数最高的学生数据放在h所指的数组中。注意:分数高的学生可能不只一个,函数返回分数最高学生的人数。
注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序: */
#include 41、TREC;
int fun (STREC *a, STREC *b)
{
/*************Begin*************/
/*************End*************/
}
void main ()
{
FILE *wf;
STREC s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
{"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87},
{"GA015",85},{"GA01 42、3",91},{"GA012",64},{"GA014",91},
{"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};
STREC h[N];
int i, n;
n=fun(s,h);
printf("The %d highest score :\n",n);
for (i=0; i 43、/
wf=fopen("debug\\out27.dat","w");
fprintf(wf, "%d\n",n);
for (i=0; i 44、].s;/*找出最大值*/
for(i=0;i 45、的结构。
试题程序:*/
#include 46、i=0;i 47、s Mark=%d\n ",
a[i].num, a[i].s);
fprintf(pf, "\n\n ");
}
void main()
{ STU a[N]={{ "A01 ",81},{ "A02 ",89},{ "A03 ",66},{ "A04 ",87},{ "A05 ",77},
{ "A06 ",90},{ "A07 ",79},{ "A08 ",61},{ "A09 ",80},{ "A10 ",71}};
STU *pOrder;
int i, m;
printf("*****THE RESULT*****\n");
out 48、result(a,stdout);
printf("\nGive the number of the students who have better score: ");
scanf("%d",&m);
while(m>10)
{ printf("\nGive the number of the students who have better score: ");
scanf("%d",&m);
}
pOrder=fun(a,m);
printf("***** THE RESULT*****\n");
printf("The to 49、p :\n");
for(i=0;i 50、也不得更改程序的结构。
试题程序: */
#include






