全国计算机等级考试二级题库【C语言】:程序填空题型——结构体 自制答案详解合辑

发布于:2025-07-24 ⋅ 阅读:(27) ⋅ 点赞:(0)

二级C语言程序填空题型简介

1、/**********found**********/紧跟的下面一行的程序设空,一般为3个空;
2、常见错误:
(1)
(2)
3、做题推荐步骤:
(1)
(2)

---------------一、结构体---------------

2、题目要求【结构体】

程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是对形参b所指结构体变量中的数据进行修改,最后在主函数中输出修改后的数据。 例如:b所指变量t中的学号、姓名和三门课的成绩依次是:10002、“ZhangQi”、93.00、85.00、87.00,修改后输出t中的数据应为: 10004、“LiJie”、93.00、85.00、87.00。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!

#include  <stdio.h>
#include  <string.h>
struct student {
   
   
  long  sno;
  char  name[10];
  float  score[3];
};
void fun( struct student  *b)
{
   
   
/**********found**********/
  b__1__ = 10004;
/**********found**********/
  strcpy(b__2__, "LiJie");
}
main()
{
   
    struct student  t={
   
   10002,"ZhangQi", 93, 85, 87};
  int  i;
  printf("\n\nThe original data :\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");
/**********found**********/
  fun(__3__);
  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");
  getchar();
}

我的答案

#include  <stdio.h>
#include  <string.h>
struct student {
   
   
  long  sno;
  char  name[10];
  float  score[3];
};
void fun( struct student  *b)
{
   
   
/**********found**********/
  b->sno = 10004;//(1)结构体指针变量 访问属性的方式 ->
/**********found**********/
  strcpy(b->name, "LiJie");//(2)结构体指针变量 访问属性的方式 ->
}
main()
{
   
    struct student  t={
   
   10002,"ZhangQi", 93, 85, 87};
  int  i;
  printf("\n\nThe original data :\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");
/**********found**********/
  fun(&t);//(3)函数调用 参数为指针类型的
  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");
  getchar();
}

知识点提要
1、结构体:结构体指针变量属性的访问->;普通结构体面两属性的访问.;(考察知识)
2、指针:指针变量就是记录地址值的变量;指针变量的赋值;指针作为函数的参数。(考察知识)

技巧总结
1、变量赋值所在行,结构体的属性缺失:①根据右值确定属性;②根据变量类型确定访问运算符为->还是.
2、函数调用所在行,参数缺失:①查看函数定义时的参数列表中的形参类型;②检查所在代码块相关变量的类型。

4、题目要求【结构体】

程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。函数fun的功能是将形参a所指结构体变量s中的数据进行修改,并把a中地址作为函数值返回主函数,在主函数中输出修改后的数据。例如: a所指变量s中的学号、姓名、和三门课的成绩依次是: 10001、 ”ZhangSan”、95、80、88, 修改后输出t所指变量的数据应为: 10002、 "LiSi”、96、81、89。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在文件BLANK1. C中,不得增行或删行,也不得更改程序的结构。

#include  <stdio.h>
#include  <string.h>
struct student {
   
   
  long  sno;
  char  name[10];
  float  score[3];
};
/**********found**********/
__1__ fun(struct student  *a)
{
   
    int  i;
  a->sno = 10002;
  strcpy(a->name, "LiSi");
/**********found**********/
  for (i=0; i<3; i++) __2__ += 1;
/**********found**********/
  return __3__ ;
}
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");
  getchar();
}

我的答案

#include  <stdio.h>
#include  <string.h>
struct student {
   
   
  long  sno;
  char  name[10];
  float  score[3];
};
/**********found**********/
struct student* fun(struct student  *a)//(1)函数返回值类型缺失
{
   
    int  i;
  a->sno = 10002;
  strcpy(a->name, "LiSi");
/**********found**********/
  for (i=0; i<3; i++) a->score[i] += 1;//(2)for循环中,赋值语句左值缺失
/**********found**********/
  return a;//(3)函数返回值缺失
}
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")

网站公告

今日签到

点亮在社区的每一天
去签到