二级题目3
二、程序填空 ??共1题 (共计20分)
第1题 (10.0分) ???????题号:35 ???????难度:难 ???????第9章
/*-------------------------------------------------------
【程序填空】
---------------------------------------------------------
题目:程序通过定义学生结构体变量,存储学生的学号、姓名和3门课的成绩。函数fun的功
??????能是:将形参a中的数据进行修改,把修改后的数据作为函数值返回主函数进行输出。
例如:若传给形参a的数据中学号、姓名和三门课的成绩依次是:
??????10001、"ZhangSan"、95、80、88,修改后的数据应为:
??????10002、"LiSi"、96、81、89。
-------------------------------------------------------*/
#include ??<stdio.h>
#include ??<string.h>
struct student
{
????????long ?sno;
????????char ?name[10];
????????float ?score[3];
};
/***********SPACE***********/
struct ?student fun( 【?】 )
{
????????int ?i;
????????a.sno = 10002;
/***********SPACE***********/
????????strcpy(【?】, "LiSi");
????????for (i=0; i<3; i++)
/***********SPACE***********/
????????????????【?】+= 1;
????????return ?a;
}
main()
{
????????struct student ?s={10001,"ZhangSan", 95, 80, 88}, t;
????????int ?i;
????????printf("\n\nThe original data :\n");
????????printf("\nNo: %ld ?Name: %s\nScores: ?",s.sno, s.name);
????????for (i=0; i<3; i++)
????????????????printf("%6.2f ", s.score[i]);
????????printf("\n");
????????t = fun(s);
????????printf("\nThe data after modified :\n");
????????printf("\nNo: %ld ?Name: %s\nScores: ?",t.sno, t.name);
????????for (i=0; i<3; i++)
????????????????printf("%6.2f ", t.score[i]);
????????printf("\n");
}
三、程序改错 ??共2题 (共计20分)
第1题 (10.0分) ???????题号:42 ???????难度:中 ???????第9章
/*-------------------------------------------------------
【程序改错】
---------------------------------------------------------
题目:下列给定程序中,函数fun的功能是:对N名学生的学习成绩,按从高到低的顺序找
??????出前m(m≤10)名学生来,并将这些学生的数据存放在一个动态分配的连续存储区中,
??????此存储区的首地址作为函数值返回。
-------------------------------------------------------*/
#include <stdlib.h>
#include ?<conio.h>
#include ?<string.h>
#include ?<stdio.h>
#include ?<malloc.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++)
????????{ ???????
????????????????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 ");
}
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;
????????system("CLS");
????????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("\nGive the number of the students who have better score: ");
????????????????scanf("%d",&m);
????????}
????????pOrder=fun(a,m);
????????printf("***** THE RESULT*****\n");
????????printf("The top :\n");
????????for(i=0;i<m;i++)
????????????????printf("%s ?%d\n",pOrder[i].num, pOrder[i].s);
????????free(pOrder);
}
第2题 (10.0分) ???????题号:86 ???????难度:中 ???????第9章
/*-------------------------------------------------------
【程序改错】
---------------------------------------------------------
题目:下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。
??????函数fun的功能是将单向链表结点(不包括头结点)数据域为偶数的值累加起来,
??????并且作为函数值返回。
-------------------------------------------------------*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct aa
{
????????int data;
????????struct aa *next;
} NODE;
int fun (NODE *h)
{
????????int sum=0;
????????NODE *p;
????????p=h->next;
/***********FOUND***********/
????????while(p->next)
????????{
????????????????if(p->data%2==0)
????????????????????????sum+=p->data;
????????/***********FOUND***********/
????????????????????????p=h->next;
????????}
????????return sum;
}
NODE *creatlink(int n)
{
????????NODE *h,*p,*s;
????????int i;
????????h=p=(NODE*)malloc(sizeof(NODE));
????????for(i=1;i<n;i++)
????????{
????????????????s=(NODE*)malloc(sizeof(NODE));
????????????????s->data=rand()%16;
????????????????s->next=p->next;
????????????????p->next=s;
????????????????p=p->next;
????????}
????????p->next=NULL;
????????return h;
}
outlink(NODE *h)
{
????????NODE ?*p;
????????p=h->next;
????????printf("\n\n The LIST :\n\n HEAD");
????????while(p)
????????{
????????????????printf("->%d",p->data);
????????????????p=p->next;
????????}
????????printf("\n");
}
void main()
{
????????NODE *head; int sum;
????????system("CLS");
????????head=creatlink(10);
????????outlink(head);
????????sum=fun(head);
????????printf("\nSUM=%d",sum);
}
四、程序设计 ??共1题 (共计10分)
第1题 (10.0分) ???????题号:154 ???????难度:较难 ???????第9章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中。
??????请编写函数fun,其功能是:把指定分数范围内的学生数据放在b所指的数组中,分
??????数范围内的学生人数由函数值返回。
例如:输入的分数是60、69,则应当把分数在60~69的学生数据输出,包含60分和69分的学
??????生数据。主函数中把60放在low中,把69放在heigh中。
注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
??????你编写的若干语句。
-------------------------------------------------------*/
#include <stdio.h>
#define ??N ??16
typedef ?struct
{ ?
????????char ?num[10];
????????int ??s;
} STREC;
int ?fun( STREC ?*a,STREC *b,int l, int h )
{
/**********Program**********/
/********** ?End ?**********/
}
void main()
{ ?
????????STREC ?s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
????????????????{"GA001",96},{"GA007",72},{"GA008",64},{"GA006",87},
????????????????{"GA015",85},{"GA013",94},{"GA012",64},{"GA014",91},
????????????????{"GA011",90},{"GA017",64},{"GA018",64},{"GA016",72}};
????????STREC ?h[N];
????????int ?i,n,low,heigh,t;
????????printf("Enter 2 integer number low & heigh : ?");
????????scanf("%d%d", &low,&heigh);
????????if ( heigh< low )
????????{
????????????????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<n; i++)
????????????????printf("%s ?%4d\n",h[i].num,h[i].s);
????????printf("\n");
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!