设为首页 加入收藏

TOP

计算机等级考试二级C语言程序设计专项训练题——程序填空题(二)(一)
2023-07-23 13:32:24 】 浏览:412
Tags:计算机 程序设 计专项 程序填 空题

11、人员的记录由编号和出生年、月、日组成,N名人员的数据已在主函数中存入结构体数组std中。函数fun的功能是:找出指定出生年份的人员,将其数据放在形参k所指的数组中,由主函数输出,同时由函数值返回满足指定条件的人数。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#define N 8
typedef  struct
{  int  num;
   int  year,month,day ;
}STU;
int fun(STU  *std, STU  *k, int  year)
{  int  i,n=0;
   for (i=0; i<N; i++)
/**********found**********/
      if(  ___1___==year)
/**********found**********/
         k[n++]= ___2___;
/**********found**********/
   return (___3___);
}
int main()
{  
   STU  std[N]={ {1,1984,2,15},{2,1983,9,21},{3,1984,9,1},{4,1983,7,15},
                 {5,1985,9,28},{6,1982,11,15},{7,1982,6,22},{8,1984,8,19}};
   STU  k[N];         
   int  i,n,year;
   printf("Enter a year :  ");  scanf("%d",&year);
   n=fun(std,k,year);
   if(n==0)
      printf("\nNo person was born in %d \n",year);
   else
   {   printf("\nThese persons were born in %d \n",year);
       for(i=0; i<n; i++)
         printf("%d  %d-%d-%d\n",k[i].num,k[i].year,k[i].month,k[i].day);
   }
   return 0;
}

12、给定程序中,函数fun的功能是:将形参指针所指结构体数组中的三个元素按num成员进行升序排列。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
typedef struct
{  int  num;
   char  name[10];
}PERSON;
/**********found**********/
void fun(PERSON  ___1___)
{
/**********found**********/
   ___2___  temp;
   if(std[0].num>std[1].num)
  {  temp=std[0];  std[0]=std[1];  std[1]=temp;  }
   if(std[0].num>std[2].num)
  {  temp=std[0];  std[0]=std[2];  std[2]=temp; }
   if(std[1].num>std[2].num)
  {  temp=std[1];  std[1]=std[2];  std[2]=temp;  }
}
int main()
{  
   PERSON  std[ ]={ 5,"Zhanghu",2,"WangLi",6,"LinMin" };
   int  i;
/**********found**********/
   fun(___3___);
   printf("\nThe result is :\n");
   for(i=0; i<3; i++)
      printf("%d,%s\n",std[i].num,std[i].name);
   return 0;
}

13、下列给定程序中,函数fun的功能是:在带头结点的单向链表中,查找数据域中值为ch的结点。找到后通过函数值返回该结点在链表中所处的顺序号;若不存在值为ch的结点,函数返回0值。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!

#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef  struct list
{  int  data;
   struct list  *next;
} SLIST;
SLIST *creatlist(char  *);
void outlist(SLIST  *);
int fun( SLIST  *h, char  ch)
{  SLIST  *p;        int  n=0;
   p=h->next;
/**********found**********/
   while(p!=___1___)
   {   n++;
/**********found**********/
       if (p->data==ch)  return ___2___;
       else  p=p->next;
   }
   return 0;
}
int main()
{  SLIST  *head;       int  k;      char  ch;
   char  a[N]={'m','p','g','a','w','x','r','d'};
   head=creatlist(a);
   outlist(head);
   printf("Enter a letter:");
   scanf("%c",&ch);
/**********found**********/
   k=fun(___3___);
   if (k==0)   printf("\nNot found!\n");
   else       printf("The sequence number is :  %d\n",k);
   return 0;
}
SLIST *creatlist(char  *a)
{  SLIST  *h,*p,*q;      int  i;
   h=p=(SLIST *)malloc(sizeof(SLIST));
   for(i=0; i<N; i++)
   {  q=(SLIST *)malloc(sizeof(SLIST));
      q->data=a[i];  p->next=q;  p=q;
   }
   p->next=0;
   return  h;
}
void outlist(SLIST  *h)
{  SLIST  *p;
   p=h->next;
   if (p==NULL)  printf("\nThe list is NULL!\n");
  else
  {  printf("\nHead");
     do
     { printf("->%c",p->data);  p=p->next;  }
     while(p!=NULL);
     printf("->End\n");
  }
}

14、给定程序中,函数fun的功能是将形参给定的字符串、整数、浮点数写到文本文件中,再用字符方式从此文本文件中逐个读入并显示在终端屏幕

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇计算机等级考试二级C语言程序设计.. 下一篇OpenGL ES OpenGL WebGL EGL WGL ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目