内容正文:
编写说明:湖南省普通高校对口招生专业理论考试《计算机应用类专业综合考纲百套卷》,依据《湖南省普通高校对口招生计算机应用类专业综合知识基本要求及考试大纲》编写。每门课程均分三层训练:基础层(具象化支架)拆解考点为微目标,紧扣考纲 “掌握”“理解” 要求编写考点训练卷;巩固层(关联性支架)强化知识交叉与场景关联,按考纲专题编专题训练卷;应用层(引导性支架)聚焦真题突破,结合知识模块与教材编写课程综合卷。
本试卷是第83卷,按《计算机编程语言——C语言》范围和要求编写。具体内容为:①结构体数组的定义;②结构体数组的初始化;③共用体变量的定义和使用;④使用枚举类型。
湖南省《计算机应用类专业综合考纲百套卷》 第83卷
《计算机编程语言——C语言》
结构体数组、共用体和枚举类型
考点训练卷
考试时间60分钟 满分100分
班级________姓名________学号________成绩________
一、单项选择题(本大题共15小题,每题2分,共30分)
1.设有语句:struct Stu{ int id;};,( )
A. struct Stu s[5]; B. struct Stu[5] s;
C. Stu s[5]; D. struct Stu s5[];
2.设有结构体数组初始化代码:struct Num{ int x; } arr[3] = {{10}, {20}};,下列说法正确的是( )
A. 数组仅有 2 个有效元素,编译报错 B. arr[2].x 的值为 0
C. arr[2].x 是随机垃圾值 D. 该初始化格式语法错误
3.以下关于共用体的核心特点,描述错误的是( )
A. 共用体所有成员共享同一块内存空间
B. 同一时刻,共用体只能有效保存一个成员的数据
C. 共用体变量定义时,系统分配内存以最大成员为准
D. 共用体可以直接整体赋值给另一个共用体变量
4.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Data
{ int a;} d[2] = {{5}, {8}};
int main()
{ int sum = d[0].a + d[1].a;
printf("%d", sum); }
A. 5 B. 8 C. 13 D. 0
5.执行以下程序段的输出结果是( )
#include<stdio.h>
union U
{ int m; int n;};
int main()
{ union U u;
u.m = 66;
printf("%d", u.n); }
A. 0 B. 66 C. 随机值 D. 编译错误
6.设有定义:enum Week {Mon, Tue, Wed, Thu};,则枚举常量 Tue 对应的整数值是( )
A. 0 B. 1 C. 2 D. 3
7.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Point
{ int x;
int y;} p[2] = {{1,2}, {3,4}};
int main()
{ int res = p[0].y + p[1].x;
printf("%d", res); }
A. 4 B. 5 C. 6 D. 7
8.执行以下程序段的输出结果是( )
union Score
{ int s1; int s2;};
void fun(union Score t)
{ t.s2 = 90;}
int main()
{ union Score sc;
sc.s1 = 80;
fun(sc); printf("%d", sc.s1);}
A. 80 B. 90 C. 0 D. 随机值
9.设有定义:enum Fruit {Apple=5, Banana, Orange};,枚举常量 Orange 的值是( )
A. 5 B. 6 C. 7 D. 8
10.设有定义:union U1{ char ch;int num;};,该共用体变量占用内存大小由哪个成员决定( )
A. Ch B. num C. 两个成员之和 D. 不确定
11.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Box
{ int len;} b[3] = { {11} };
int main()
{ printf("%d", b[2].len);}
A. 11 B. 0 C. 随机值 D. 编译报错
12.设有定义:enum Dir {Left=2, Right, Up=7, Down};,常量 Down 的值为( )
A. 7 B. 8 C. 9 D. 3
13.设有定义:struct S {int a; int b;};,则以下关于结构体数组初始化,语法错误的是( )
A. struct S s[2] = { {1,2}, {3,4} };
B. struct S s[2] = {1,2,3,4};
C. struct S s[2] = { {1} };
D. struct S s[2] = (1,2), (3,4);
14.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Age
{ int age;} ag[3] = {{10}, {20}, {30}};
int main()
{ int i, total = 0;
for(i=0; i<3; i++)
total += ag[i].age;
printf("%d", total);}
A. 30 B. 50 C. 60 D. 0
15.执行以下程序段的输出结果是( )
#include<stdio.h>
union U2
{ int a; int b;};
int main()
{ union U2 u;
u.a = 12;
u.b = 24;
printf("%d", u.a); }
A. 12 B. 24 C. 36 D. 0
二、阅读程序,写出运行结果(本大题共10小题。每空2分,合计20分)
1.下列程序的运行结果是__________________。
#include<stdio.h>
struct Game
{ int lv;} g[3] = {{2}};
int main()
{ int k = 0;
while(k < 3)
{
g[k].lv += 1;
k++;
}
printf("%d", g[2].lv);}
2.下列程序的运行结果是__________________。
#include<stdio.h>
struct Node
{ int n;} nd[2] = {{7}, {9}};
void show(struct Node t)
{ t.n += 3;}
int main()
{ show(nd[0]);
printf("%d", nd[0].n);}
3.下列程序的运行结果是__________________。
#include <stdio.h>
struct Student
{ int score;};
int main()
{ struct Student st[4] = {{65},{72},{60},{55}};
int i, cnt = 0;
for(i = 0; i < 4; i++)
{ if(st[i].score > 60)
cnt++; }
printf("%d", cnt);
return 0;}
4.下列程序的运行结果是__________________。
#include <stdio.h>
union Data
{ long num;
char ch;};
int main()
{ union Data d;
d.num = 100;
d.ch = 'A';
printf("%ld", d.num);
return 0; }
5.下列程序的运行结果是__________________。
#include <stdio.h>
struct Goods
{ int price; int num;};
int main()
{ struct Goods g[2] = {{28, 5}, {36, 2}};
int total = g[0].price * g[0].num + g[1].price * g[1].num;
printf("%d", total);
return 0; }
6.下列程序的运行结果是__________________。
#include <stdio.h>
union Tag
{ int x; double y;};
void change(union Tag t)
{ t.x = 200;}
int main()
{ union Tag tg;
tg.y = 3.14;
change(tg);
printf("%.2f", tg.y);
return 0;}
7.下列程序的运行结果是__________________。
#include <stdio.h>
enum Sign {Neg = -1, Zero, Pos};
int main()
{ int val = 8;
enum Sign s;
if(val < 0)
s = Neg;
else if(val == 0)
s = Zero;
else
s = Pos;
printf("%d", s);
return 0; }
8.下列程序的运行结果是__________________。
#include <stdio.h>
struct Player
{ int hp;} p[3] = {{90}};
int main()
{ int i;
for(i = 0; i < 3; i++)
{
p[i].hp -= 10;
}
printf("%d", p[2].hp);
return 0; }
9.下列程序的运行结果是__________________。
#include <stdio.h>
struct Book
{ int pages;};
struct Book getBook()
{ struct Book b;
b.pages = 156;
return b;}
int main()
{ struct Book bk[2];
bk[1] = getBook();
printf("%d", bk[1].pages);
return 0;}
10.下列程序的运行结果是__________________。
#include <stdio.h>
struct Exam
{ int sub;};
int main()
{ struct Exam e[3] = {{82}, {91}, {76}};
int max = e[0].sub, i;
for(i = 1; i < 3; i++)
{ if(e[i].sub > max)
max = e[i].sub;
}
printf("%d", max);
return 0;}
三、程序填空。按照题目要求,将正确内容填入答题卡相应位置,使程序完整(每空2分,共计30分)
1.下列程序代码的功能是:定义结构体保存年、月、日,由用户输入一个合法日期,程序计算并输出该日期的下一天日期(自动处理月末、年末、闰年2月边界)。
#include <stdio.h>
struct Date
{ int year;
int month;
int day;};
int isLeap(int y)
{ if(______________①_____________)
return 1;
return 0;}
int getDays(int y, int m)
{ switch(______②_______)
{ case 1:case 3:case 5:case 7:case 8:case 10:case 12: return 31;
case 4:case 6:case 9:case 11: return 30;
case 2: return _________③________;
default: return 0; }
}
int main()
{ struct Date dt;
int maxDay;
printf("请输入 年 月 日:");
scanf("%d %d %d", &dt.year, &dt.month, &dt.day);
dt.day++;
maxDay = getDays(dt.year, dt.month);
if(dt.day > maxDay)
{ dt.day = 1;
_______④_______;
if(_____⑤______)
{ dt.month = 1;
dt.year++; }
}
printf("次日日期:%d年%d月%d日
", dt.year, dt.month, dt.day);
return 0;}
2.下列程序代码的功能是:定义结构体数组存储 3 组矩形长宽数据,批量计算每组矩形的面积,找出面积最大的矩形序号与面积值。
#include <stdio.h>
struct Rect
{ int len;
int wid;};
int main()
{ struct Rect rec[3];
int i, area, maxArea = 0, idx = 0;
for(i=0; _____①_____; i++)
{ printf("请输入第%d个矩形 长 宽:", i+1);
scanf("%d %d", &rec[i].len, &rec[i].wid);
}
for(i=0; i<3; i++)
{ area = ________②________;
if(______③______)
{ maxArea = area;
idx = ______④_____; }
}
printf("面积最大的是第%d个矩形,面积 = %d
", idx, maxArea);
return 0; }
3.下列程序代码的功能是:结构体存储书本编号、页数,结构体数组遍历查找页数最多的书籍编号与页数。
#include <stdio.h>
_______①________
{ int bookId;
int page;};
int main()
{ struct Book b[4];
int i, maxPage = 0, bid = 0;
for(i=0; i<4; i++)
{ printf("书籍%d 编号 页数:", i+1);
scanf("%d %d", &b[i].bookId, &b[i].page);
if(_________②_________)
{
_________③________;
bid = b[i].bookId;
}
}
printf("页数最多的书籍:编号%d,共%d页
", bid, maxPage);
return 0; }
4.下列程序代码的功能是:结构体数组存储 4 组仓库货物:编号、库存数量,遍历数组统计库存大于 100 的货物总数。
#include <stdio.h>
struct GoodsStore
{ int goodsId;
int stock;};
int main()
{
________①________
int i, count = 0;
for(i = 0; i < 4; i++)
{
printf("第%d件货物 编号 库存:", i+1);
scanf("%d %d", &gs[i].goodsId, &gs[i].stock);
if(_________②________)
_________③_________
}
printf("库存超100的货物共有:%d 件
", count);
return 0; }
四、阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构。请在答题卡中指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共计20分)
1.下列程序代码的功能是:定义结构体数组存储多组日期,批量输入 3 个日期,逐一判断每个日期是否为当月最后一天,并输出判断结果。以下程序只允许修改三行。
L1 #include <stdio.h>
L2 struct Date
L3 { int y; int m; int d;};
L4 int leap(int y)
L5 { return (y%4==0 && y%100!=0) || (y%400==0);}
L6 int monthDay(int y, int m)
L7 { if(m==2) return leap(y) ? 28 : 29;
L8 if(m==4||m==6||m==9||m==11) return 30;
L9 return 31;}
L10 int main()
L11 { struct Date date[3];
L12 int i;
L13 for(i=0; i<3; i++)
L14 { printf("请输入第%d个日期(年 月 日):", i+1);
L15 scanf("%d %d %d", date[i].y, date[i].m, date[i].d);
L16 }
L17 for(i=0; i<3; i++)
L18 { int total = monthDay(date[i].y, date[i].m);
L19 if(date[i].d = total)
L20 printf("第%d个日期是当月最后一天
", i+1);
L21 else
L22 printf("第%d个日期不是当月最后一天
", i+1);
L23 }
L24 return 0; }
2.下列程序代码的功能是:定义学生结构体(学号、成绩),结构体数组存储 5 名学生成绩,统计总分、平均分(精确至小数点后2位)、及格人数(≥60 分为及格)。以下程序只允许修改三行。
L1 #include <stdio.h>
L2 struct Student
L3 { int id;
L4 int score;};
L5 int main()
L6 { struct Student stu[5];
L7 int i, sum = 0, pass = 0;
L8 double avg;
L9 for(i=0; i<5; i++)
L10 { printf("请输入第%d名学生 学号 成绩:", i+1);
L11 scanf("%d %d", &stu[i].id, &stu[i].score);
L12 sum = stu[i].score;
L13 if(stu[i].score > 60)
L14 pass++;
L15 }
L16 avg = sum / 5;
L17 printf("总分:%d
", sum);
L18 printf("平均分:%.2f
", avg);
L19 printf("及格人数:%d
", pass);
L20 return 0; }
3.下列程序代码的功能是:结构体数组存储 4 件商品(单价、数量),模拟超市结算,计算所有商品总金额,并判断消费金额是否满 100 元。以下程序只允许修改两行。
L1 #include <stdio.h>
L2 struct
L3 { int price;
L4 int num;};
L5 int main()
L6 { struct Goods goods[4];
L7 int i, total = 0;
L8 for(i=0; i<4; i++)
L9 { printf("第%d件商品 单价 数量:", i+1);
L10 scanf("%d %d", &goods[i].price, &goods[i].num);
L11 total = goods[i].price * goods[i].num;
L12 }
L13 printf("消费总金额:%d 元
", total);
L14 if(total >= 100)
L15 printf("消费满100元
");
L16 else
L17 printf("消费未满100元
");
L18 return 0; }
4.下列程序代码的功能是:结构体数组存储 3 台设备编号、运行时长,计算所有设备的总运行时长与平均时长(数据精确到小数位后2位)。以下程序只允许修改两行。
L1 #include <stdio.h>
L2 struct Machine
L3 { int macId;
L4 int hour;};
L5 int main()
L6 { struct Machine mac[];
L7 int i, total = 1;
L8 double avg;
L9 for(i = 0; i < 3; i++)
L10 {
L11 printf("设备%d 编号 运行时长(小时):", i+1);
L12 scanf("%d %d", &mac[i].macId, &mac[i].hour);
L13 total += mac[i].hour;
L14 }
L15 avg = total / 3.0;
L16 printf("总运行时长:%d 小时
", total);
L17 printf("平均运行时长:%.2f 小时
", avg);
L18 return 0;}
原创精品资源学科网独家享有版权,侵权必究!
学科网(北京)股份有限公司
学科网(北京)股份有限公司
学科网(北京)股份有限公司
$
编写说明:湖南省普通高校对口招生专业理论考试《计算机应用类专业综合考纲百套卷》,依据《湖南省普通高校对口招生计算机应用类专业综合知识基本要求及考试大纲》编写。每门课程均分三层训练:基础层(具象化支架)拆解考点为微目标,紧扣考纲 “掌握”“理解” 要求编写考点训练卷;巩固层(关联性支架)强化知识交叉与场景关联,按考纲专题编专题训练卷;应用层(引导性支架)聚焦真题突破,结合知识模块与教材编写课程综合卷。
本试卷是第83卷,按《计算机编程语言——C语言》范围和要求编写。具体内容为:①结构体数组的定义;②结构体数组的初始化;③共用体变量的定义和使用;④使用枚举类型。
湖南省《计算机应用类专业综合考纲百套卷》 第83卷
《计算机编程语言——C语言》
结构体数组、共用体和枚举类型
考点训练卷
考试时间60分钟 满分100分
班级________姓名________学号________成绩________
一、单项选择题(本大题共15小题,每题2分,共30分)
1.设有语句:struct Stu{ int id;};,( )
A. struct Stu s[5]; B. struct Stu[5] s;
C. Stu s[5]; D. struct Stu s5[];
【答案】A
【解析】结构体数组标准写法:struct 结构体名 数组名[长度]。B 语序错误;C 未用typedef别名,不能省略struct;D 数组标识写法非法。
2.设有结构体数组初始化代码:struct Num{ int x; } arr[3] = {{10}, {20}};,下列说法正确的是( )
A. 数组仅有 2 个有效元素,编译报错 B. arr[2].x 的值为 0
C. arr[2].x 是随机垃圾值 D. 该初始化格式语法错误
【答案】B
【解析】结构体数组部分初始化,未显式初始化的数组元素,其所有成员自动置 0。
3.以下关于共用体的核心特点,描述错误的是( )
A. 共用体所有成员共享同一块内存空间
B. 同一时刻,共用体只能有效保存一个成员的数据
C. 共用体变量定义时,系统分配内存以最大成员为准
D. 共用体可以直接整体赋值给另一个共用体变量
【答案】D
【解析】C 语言不支持共用体整体赋值、整体比较;A、B、C 均为共用体基本特性。
4.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Data
{ int a;} d[2] = {{5}, {8}};
int main()
{ int sum = d[0].a + d[1].a;
printf("%d", sum); }
A. 5 B. 8 C. 13 D. 0
【答案】C
【解析】d[0].a=5,d[1].a=8,求和 5+8=13。
5.执行以下程序段的输出结果是( )
#include<stdio.h>
union U
{ int m; int n;};
int main()
{ union U u;
u.m = 66;
printf("%d", u.n); }
A. 0 B. 66 C. 随机值 D. 编译错误
【答案】B
【解析】共用体成员共享内存,给m赋值后,同内存的n读取到相同数值。
6.设有定义:enum Week {Mon, Tue, Wed, Thu};,则枚举常量 Tue 对应的整数值是( )
A. 0 B. 1 C. 2 D. 3
【答案】B
【解析】枚举默认从0开始依次递增:Mon=0、Tue=1、Wed=2、Thu=3。
7.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Point
{ int x;
int y;} p[2] = {{1,2}, {3,4}};
int main()
{ int res = p[0].y + p[1].x;
printf("%d", res); }
A. 4 B. 5 C. 6 D. 7
【答案】B
【解析】p[0].y=2,p[1].x=3,2+3=5。
8.执行以下程序段的输出结果是( )
union Score
{ int s1; int s2;};
void fun(union Score t)
{ t.s2 = 90;}
int main()
{ union Score sc;
sc.s1 = 80;
fun(sc); printf("%d", sc.s1);}
A. 80 B. 90 C. 0 D. 随机值
【答案】A
【解析】共用体变量作为函数参数是值传递,函数内修改形参不影响主函数实参,sc.s1 仍为 80。
9.设有定义:enum Fruit {Apple=5, Banana, Orange};,枚举常量 Orange 的值是( )
A. 5 B. 6 C. 7 D. 8
【答案】C
【解析】手动指定Apple=5,后续常量依次自增:Banana=6,Orange=7。
10.设有定义:union U1{ char ch;int num;};,该共用体变量占用内存大小由哪个成员决定( )
A. Ch B. num C. 两个成员之和 D. 不确定
【答案】B
【解析】共用体内存 = 内部占用字节最大的成员,int 字节数大于 char,由 num 决定。
11.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Box
{ int len;} b[3] = { {11} };
int main()
{ printf("%d", b[2].len);}
A. 11 B. 0 C. 随机值 D. 编译报错
【答案】B
【解析】结构体数组仅初始化第 0 个元素,剩余元素成员全部自动置 0。
12.设有定义:enum Dir {Left=2, Right, Up=7, Down};,常量 Down 的值为( )
A. 7 B. 8 C. 9 D. 3
【答案】B
【解析】Up=7,后续Down在上一个常量基础 + 1,结果为 8。
13.设有定义:struct S {int a; int b;};,则以下关于结构体数组初始化,语法错误的是( )
A. struct S s[2] = { {1,2}, {3,4} };
B. struct S s[2] = {1,2,3,4};
C. struct S s[2] = { {1} };
D. struct S s[2] = (1,2), (3,4);
【答案】D
【解析】结构体 / 结构体数组初始化必须使用{},圆括号()用于表达式,语法非法。
14.执行以下程序段的输出结果是( )
#include<stdio.h>
struct Age
{ int age;} ag[3] = {{10}, {20}, {30}};
int main()
{ int i, total = 0;
for(i=0; i<3; i++)
total += ag[i].age;
printf("%d", total);}
A. 30 B. 50 C. 60 D. 0
【答案】C
【解析】累加 10+20+30=60。
15.执行以下程序段的输出结果是( )
#include<stdio.h>
union U2
{ int a; int b;};
int main()
{ union U2 u;
u.a = 12;
u.b = 24;
printf("%d", u.a); }
A. 12 B. 24 C. 36 D. 0
【答案】B
【解析】共用体同一时刻仅最后一次赋值有效,先给a=12,再覆盖为b=24,最终a读取 24。
二、阅读程序,写出运行结果(本大题共10小题。每空2分,合计20分)
1.下列程序的运行结果是__________________。
#include<stdio.h>
struct Game
{ int lv;} g[3] = {{2}};
int main()
{ int k = 0;
while(k < 3)
{
g[k].lv += 1;
k++;
}
printf("%d", g[2].lv);}
【答案】1
2.下列程序的运行结果是__________________。
#include<stdio.h>
struct Node
{ int n;} nd[2] = {{7}, {9}};
void show(struct Node t)
{ t.n += 3;}
int main()
{ show(nd[0]);
printf("%d", nd[0].n);}
【答案】7
3.下列程序的运行结果是__________________。
#include <stdio.h>
struct Student
{ int score;};
int main()
{ struct Student st[4] = {{65},{72},{60},{55}};
int i, cnt = 0;
for(i = 0; i < 4; i++)
{ if(st[i].score > 60)
cnt++; }
printf("%d", cnt);
return 0;}
【答案】2
4.下列程序的运行结果是__________________。
#include <stdio.h>
union Data
{ long num;
char ch;};
int main()
{ union Data d;
d.num = 100;
d.ch = 'A';
printf("%ld", d.num);
return 0; }
【答案】65
5.下列程序的运行结果是__________________。
#include <stdio.h>
struct Goods
{ int price; int num;};
int main()
{ struct Goods g[2] = {{28, 5}, {36, 2}};
int total = g[0].price * g[0].num + g[1].price * g[1].num;
printf("%d", total);
return 0; }
【答案】212
6.下列程序的运行结果是__________________。
#include <stdio.h>
union Tag
{ int x; double y;};
void change(union Tag t)
{ t.x = 200;}
int main()
{ union Tag tg;
tg.y = 3.14;
change(tg);
printf("%.2f", tg.y);
return 0;}
【答案】3.14
7.下列程序的运行结果是__________________。
#include <stdio.h>
enum Sign {Neg = -1, Zero, Pos};
int main()
{ int val = 8;
enum Sign s;
if(val < 0)
s = Neg;
else if(val == 0)
s = Zero;
else
s = Pos;
printf("%d", s);
return 0; }
【答案】1
8.下列程序的运行结果是__________________。
#include <stdio.h>
struct Player
{ int hp;} p[3] = {{90}};
int main()
{ int i;
for(i = 0; i < 3; i++)
{
p[i].hp -= 10;
}
printf("%d", p[2].hp);
return 0; }
【答案】-10
9.下列程序的运行结果是__________________。
#include <stdio.h>
struct Book
{ int pages;};
struct Book getBook()
{ struct Book b;
b.pages = 156;
return b;}
int main()
{ struct Book bk[2];
bk[1] = getBook();
printf("%d", bk[1].pages);
return 0;}
【答案】156
10.下列程序的运行结果是__________________。
#include <stdio.h>
struct Exam
{ int sub;};
int main()
{ struct Exam e[3] = {{82}, {91}, {76}};
int max = e[0].sub, i;
for(i = 1; i < 3; i++)
{ if(e[i].sub > max)
max = e[i].sub;
}
printf("%d", max);
return 0;}
【答案】91
三、程序填空。按照题目要求,将正确内容填入答题卡相应位置,使程序完整(每空2分,共计30分)
1.下列程序代码的功能是:定义结构体保存年、月、日,由用户输入一个合法日期,程序计算并输出该日期的下一天日期(自动处理月末、年末、闰年2月边界)。
#include <stdio.h>
struct Date
{ int year;
int month;
int day;};
int isLeap(int y)
{ if(______________①_____________)
return 1;
return 0;}
int getDays(int y, int m)
{ switch(______②_______)
{ case 1:case 3:case 5:case 7:case 8:case 10:case 12: return 31;
case 4:case 6:case 9:case 11: return 30;
case 2: return _________③________;
default: return 0; }
}
int main()
{ struct Date dt;
int maxDay;
printf("请输入 年 月 日:");
scanf("%d %d %d", &dt.year, &dt.month, &dt.day);
dt.day++;
maxDay = getDays(dt.year, dt.month);
if(dt.day > maxDay)
{ dt.day = 1;
_______④_______;
if(_____⑤______)
{ dt.month = 1;
dt.year++; }
}
printf("次日日期:%d年%d月%d日
", dt.year, dt.month, dt.day);
return 0;}
【答案】①(y % 4 == 0 && y % 100 != 0) || (y % 400 == 0) ②m ③isLeap(y) ? 29 : 28 ④dt.month++ ⑤dt.month > 12
2.下列程序代码的功能是:定义结构体数组存储 3 组矩形长宽数据,批量计算每组矩形的面积,找出面积最大的矩形序号与面积值。
#include <stdio.h>
struct Rect
{ int len;
int wid;};
int main()
{ struct Rect rec[3];
int i, area, maxArea = 0, idx = 0;
for(i=0; _____①_____; i++)
{ printf("请输入第%d个矩形 长 宽:", i+1);
scanf("%d %d", &rec[i].len, &rec[i].wid);
}
for(i=0; i<3; i++)
{ area = ________②________;
if(______③______)
{ maxArea = area;
idx = ______④_____; }
}
printf("面积最大的是第%d个矩形,面积 = %d
", idx, maxArea);
return 0; }
【答案】①i<3 ②rec[i].len * rec[i].wid ③area > maxArea
④i + 1
3.下列程序代码的功能是:结构体存储书本编号、页数,结构体数组遍历查找页数最多的书籍编号与页数。
#include <stdio.h>
_______①________
{ int bookId;
int page;};
int main()
{ struct Book b[4];
int i, maxPage = 0, bid = 0;
for(i=0; i<4; i++)
{ printf("书籍%d 编号 页数:", i+1);
scanf("%d %d", &b[i].bookId, &b[i].page);
if(_________②_________)
{
_________③________;
bid = b[i].bookId;
}
}
printf("页数最多的书籍:编号%d,共%d页
", bid, maxPage);
return 0; }
【答案】①struct Book ②b[i].page > maxPage
③ maxPage = b[i].page
4.下列程序代码的功能是:结构体数组存储 4 组仓库货物:编号、库存数量,遍历数组统计库存大于 100 的货物总数。
#include <stdio.h>
struct GoodsStore
{ int goodsId;
int stock;};
int main()
{
________①________
int i, count = 0;
for(i = 0; i < 4; i++)
{
printf("第%d件货物 编号 库存:", i+1);
scanf("%d %d", &gs[i].goodsId, &gs[i].stock);
if(_________②________)
_________③_________
}
printf("库存超100的货物共有:%d 件
", count);
return 0; }
【答案】①struct GoodsStore gs[4]; ②gs[i].stock > 100
③count++;
四、阅读程序:修改程序中的错误,不得增行或删行,也不得更改程序结构。请在答题卡中指出错误代码所在的行号,并给出该行修改后的程序代码。(每空2分,共计20分)
1.下列程序代码的功能是:定义结构体数组存储多组日期,批量输入 3 个日期,逐一判断每个日期是否为当月最后一天,并输出判断结果。以下程序只允许修改三行。
L1 #include <stdio.h>
L2 struct Date
L3 { int y; int m; int d;};
L4 int leap(int y)
L5 { return (y%4==0 && y%100!=0) || (y%400==0);}
L6 int monthDay(int y, int m)
L7 { if(m==2) return leap(y) ? 28 : 29;
L8 if(m==4||m==6||m==9||m==11) return 30;
L9 return 31;}
L10 int main()
L11 { struct Date date[3];
L12 int i;
L13 for(i=0; i<3; i++)
L14 { printf("请输入第%d个日期(年 月 日):", i+1);
L15 scanf("%d %d %d", date[i].y, date[i].m, date[i].d);
L16 }
L17 for(i=0; i<3; i++)
L18 { int total = monthDay(date[i].y, date[i].m);
L19 if(date[i].d = total)
L20 printf("第%d个日期是当月最后一天
", i+1);
L21 else
L22 printf("第%d个日期不是当月最后一天
", i+1);
L23 }
L24 return 0; }
【答案】①L7 { if(m==2) return leap(y) ? 29 : 28;
②L15 scanf("%d %d %d", &date[i].y, &date[i].m, &date[i].d);
③L19 if(date[i].d == total)
2.下列程序代码的功能是:定义学生结构体(学号、成绩),结构体数组存储 5 名学生成绩,统计总分、平均分(精确至小数点后2位)、及格人数(≥60 分为及格)。以下程序只允许修改三行。
L1 #include <stdio.h>
L2 struct Student
L3 { int id;
L4 int score;};
L5 int main()
L6 { struct Student stu[5];
L7 int i, sum = 0, pass = 0;
L8 double avg;
L9 for(i=0; i<5; i++)
L10 { printf("请输入第%d名学生 学号 成绩:", i+1);
L11 scanf("%d %d", &stu[i].id, &stu[i].score);
L12 sum = stu[i].score;
L13 if(stu[i].score > 60)
L14 pass++;
L15 }
L16 avg = sum / 5;
L17 printf("总分:%d
", sum);
L18 printf("平均分:%.2f
", avg);
L19 printf("及格人数:%d
", pass);
L20 return 0; }
【答案】①L12 sum += stu[i].score;
②L13 if(stu[i].score >= 60)
③L16 avg = sum / 5.0; 或avg = (float)sum / 5;
3.下列程序代码的功能是:结构体数组存储 4 件商品(单价、数量),模拟超市结算,计算所有商品总金额,并判断消费金额是否满 100 元。以下程序只允许修改两行。
L1 #include <stdio.h>
L2 struct
L3 { int price;
L4 int num;};
L5 int main()
L6 { struct Goods goods[4];
L7 int i, total = 0;
L8 for(i=0; i<4; i++)
L9 { printf("第%d件商品 单价 数量:", i+1);
L10 scanf("%d %d", &goods[i].price, &goods[i].num);
L11 total = goods[i].price * goods[i].num;
L12 }
L13 printf("消费总金额:%d 元
", total);
L14 if(total >= 100)
L15 printf("消费满100元
");
L16 else
L17 printf("消费未满100元
");
L18 return 0; }
【答案】①L2 struct Goods
②L11 total += goods[i].price * goods[i].num;
4.下列程序代码的功能是:结构体数组存储 3 台设备编号、运行时长,计算所有设备的总运行时长与平均时长(数据精确到小数位后2位)。以下程序只允许修改两行。
L1 #include <stdio.h>
L2 struct Machine
L3 { int macId;
L4 int hour;};
L5 int main()
L6 { struct Machine mac[];
L7 int i, total = 1;
L8 double avg;
L9 for(i = 0; i < 3; i++)
L10 {
L11 printf("设备%d 编号 运行时长(小时):", i+1);
L12 scanf("%d %d", &mac[i].macId, &mac[i].hour);
L13 total += mac[i].hour;
L14 }
L15 avg = total / 3.0;
L16 printf("总运行时长:%d 小时
", total);
L17 printf("平均运行时长:%.2f 小时
", avg);
L18 return 0;}
【答案】①L6 { struct Machine mac[3];
②L7 int i, total = 0;
原创精品资源学科网独家享有版权,侵权必究!
学科网(北京)股份有限公司
学科网(北京)股份有限公司
学科网(北京)股份有限公司
$