当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言上机操作题及答案(74)
发布时间:2011/7/22 10:08:39 来源:城市学习网 编辑:ziteng
  一、填空题
  给定程序中,函数fun的功能是:将形参std所指结构体数组中年龄最大者的数据作为函数值返回,并在main函数中输出。
  请勿改动主函数main和其它函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。
  #include
  typedef  struct
  {
  char  name[10];
  int  age;
  } STD;
  STD fun(STD  std[], int  n)
  {
  STD  max;
  int  i;
  max = ___1___;
  for (i=1; i  if (max.age < ___2___)
  max = std[i];
  return max;
  }
  main()
  {
  STD  std[5] = {"aaa", 17, "bbb", 16, "ccc", 18, "ddd", 17, "eee", 15};
  STD  max;
  max = fun(std, 5);
  printf("\nThe result: \n");
  printf("\nName : %s,   Age :  %d\n", ___3___, max.age);
  } [NextPage]   二、改错题
  下列给定程序中,函数fun的功能是:利用插入排序法对字符串中的字符按从小到大的顺序进行排序。插入法的基本算法是:先对字符串中的头两个元素进行排序。然后把第三个字符插入到前两个字符中,插入后前三个字符依然有序,再把第四个字符插入到前三个字符中,……。待排序的字符串已在主函数中赋予。
  请改正程序中的错误,使它能得出正确的结果。
  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
  #include
  #include
  #define  N 80
  void insert(char  *aa)
  {
  int  i, j, n;
  char  ch;
  n = strlen(aa);
  for (i=1; i {
  /********found********/
  c = aa[i];
  j = i-1;
  while ((j>=0) && (ch  {
  aa[j+1] = aa[j];
  j--;
  }
  aa[j+1] = ch;
  }
  }
  main()
  {
  char  a[N] = "QWERTYUIOPASDFGHJKLMNBVCXZ";
  printf("The original string :     %s\n", a);
  insert(a);
  printf("The string after sorting :  %s\n\n", a);
  }
 [NextPage]   三、编程题
  学生的记录由学生成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把分数最低的学生数据放在h所指的数组中,注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数。
  请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
  #include
  #define    N  16
  typedef   struct
  {
  char  num[10];
  int   s;
  }  STREC;
  int  fun  ( STREC  *a,  STREC  *b )
  {
  }
  main ()
  {
  STREC  s[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  lowest  score  :\n", n);
  for (i=0;  i  printf ("%s  M\n", h[i]. num, h[i]. s);
  printf ("\n");
  out=fopen ("out.dat", "w");
  fprintf (out, "%d\n", n);
  for (i=0;  i  fprintf (out, "M\n", h[i].s);
  fclose (out );
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved