
自测练习 【自测练习】 一、基础题 l、(单选)若有如下结构变量stud的声明,则正确访问变量stud的成员num的方法 是()。 struct STUDENT int age; int num; stud; A.stud.num B.stud-num C.stud (num) D.stud[num] 2、(填空)若有如下结构变量pe的声明,可通过表达式()得到变量pe占用的内存 字节。 struct PERSON char id[10]; char name [20]; char sex; int age; float score; }pe; 3、(填空)若有如下结构变量st的声明,可通过表达式()得到变量st占用的内存 字节。 struct STUDENT { char id[10]; struct BIRTH int year;
自测练习 【自测练习】 一、基础题 1、(单选)若有如下结构变量 stud 的声明,则正确访问变量 stud 的成员 num 的方法 是( )。 struct STUDENT { int age; int num; } stud; A. stud.num B. stud-num C. stud(num) D. stud[num] 2、(填空)若有如下结构变量 pe 的声明,可通过表达式( )得到变量 pe 占用的内存 字节。 struct PERSON { char id[10]; char name[20]; char sex; int age; float score; }pe; 3、(填空)若有如下结构变量 st 的声明,可通过表达式( )得到变量 st 占用的内存 字节。 struct STUDENT { char id[10]; struct BIRTH { int year;

int month: int day; }birth; }st: 4、(填空)若有如下变量st的声明,可通过表达式()得到结构数组st占用的内存 字节。 struct STUDENT char id[10]; char name[20]; int age; float score; char sex; }st[10]: 5、(填空)若有如下变量st的声明,可通过表达式()得到结构数组st占用的内存 字节。 struct STUDENT { char id[10]; struct BIRTH int year; int month; int day; }birth; }st[5] 6、(填空)完成下面程序的填空,实现程序功能要求 /* 源文件名:CH7LX1.CPP 功能:交换结构变量st1与st2的值,然后依次输出st1与st2变量的值
int month; int day; }birth; }st; 4、(填空)若有如下变量 st 的声明,可通过表达式( )得到结构数组 st 占用的内存 字节。 struct STUDENT { char id[10]; char name[20]; int age; float score; char sex; }st[10]; 5、(填空)若有如下变量 st 的声明,可通过表达式( )得到结构数组 st 占用的内存 字节。 struct STUDENT { char id[10]; struct BIRTH { int year; int month; int day; }birth; }st[5]; 6、(填空)完成下面程序的填空,实现程序功能要求 /* 源文件名:CH7_LX1.CPP 功能:交换结构变量 st1 与 st2 的值,然后依次输出 st1 与 st2 变量的值

*/ #include void main() { struct STUDENT char id[10]; int score; }: STUDENT st1={"10001",80},st2={"10002",90}: ① t stl; ② ③ cout void main() struct MONTH { int days; char name[4]; ; MONTH months[12]={{31,"Jan"),{28,"Feb"},{31,"Mar"}, {30,"Apr",{31,"May"),{30,"Jun"}, {31,"Jul,{31,"Aug"},{30,"Sep"}, {31,"0ct"),{30,"Nov"},{31,"Dec"}; int month;
*/ #include void main() { struct STUDENT { char id[10]; int score; }; STUDENT st1 = {"10001",80}, st2 = {"10002",90}; ① t = st1; ② ③ cout void main() { struct MONTH { int days; char name[4]; }; MONTH months[12]={{31,"Jan"},{28,"Feb"},{31,"Mar"}, {30,"Apr"},{31,"May"},{30,"Jun"}, {31,"Jul"},{31,"Aug"},{30,"Sep"}, {31,"Oct"},{30,"Nov"},{31,"Dec"}}; int month;

cin >month; cout void main() struct data int i; char ch; }d: d.i=97: d.ch char(d.i); cout void main() struct DATA int x; int y; int z: }data={3,5,0}: data.z data.x data.y; cout <data.x <data.y <data.z <endl; 10、(填空)填写下面程序运行的输出结果()
cin >> month; cout void main() { struct data { int i; char ch; }d; d.i = 97; d.ch = char(d.i); cout void main() { struct DATA { int x; int y; int z; }data={3,5,0}; data.z = data.x * data.y; cout << data.x << data.y << data.z << endl; } 10、(填空)填写下面程序运行的输出结果( )

#include void main() { const int STNUM 3; struct STUDENT char id[8]; float score; }st[STNUM0={"10001”,76},{"10002”,68},{"10003”,90}: int max; STUDENT t: for(int i=0;i<STNUM-1;i++) max=i; for (int j=i+1;j<STNUM;j++) { if (st[j].score st[max].score) { max j; } t=st[i]; st[i]=st[max] st[max]=t; } for (i=0;i<STNUM;i++) { cout<<st[i].id<<","<<st[i].score<<"\n"; } }
#include void main() { const int STNUM = 3; struct STUDENT { char id[8]; float score; }st[STNUM] = {{"10001",76},{"10002",68},{"10003",90}}; int max; STUDENT t; for(int i=0; i st[max].score) { max = j; } } t=st[i]; st[i]=st[max]; st[max]=t; } for (i=0; i<STNUM; i++) { cout<<st[i].id<<","<<st[i].score<<"\n"; } }

11、(多选)若有如下结构变量s的声明,则下面说法正确的是()。 struct DATA int x; float y; }s; A.struct是用户定义的结构类型的关键字 B.DATA是用户定义的结构类型的类型名 C.s是用户声明的结构类型的变量名 D.x和y均是用户定义的结构类型的成员名 12、(多选)若有如下结构定义,则下面结构变量声明正确的是()。 struct DATA int x; float y; }: A.DATA data; B.data DATA; C.DATA data[10]; D.data DATA[10]: 13、(多选)若有如下变量st的声明,则下面正确访问变量st成员的方法有()。 struct STUDENT { char id[10]; struct BIRTH int year; int month: int day; }birth; }st[5]:
11、(多选)若有如下结构变量 s 的声明,则下面说法正确的是( )。 struct DATA { int x; float y; }s; A. struct 是用户定义的结构类型的关键字 B. DATA 是用户定义的结构类型的类型名 C. s 是用户声明的结构类型的变量名 D. x 和 y 均是用户定义的结构类型的成员名 12、(多选)若有如下结构定义,则下面结构变量声明正确的是( )。 struct DATA { int x; float y; }; A. DATA data; B. data DATA; C. DATA data[10]; D. data DATA[10]; 13、(多选)若有如下变量 st 的声明,则下面正确访问变量 st 成员的方法有( )。 struct STUDENT { char id[10]; struct BIRTH { int year; int month; int day; }birth; }st[5];

A.st[1].month B.st[1].birth.day C.st[0].id 2 st[0].birth 14、(多选)若有如下变量st的声明,则下面正确访问变量st成员的方法有()。 struct STUDENT char id[10]; char name[20] int age; float score; char sex; }st[10]: A.st.id[O] B.st[o].id C.st[o].id[o] D st[o].id[10] 二、编程题 1、编写程序实现功能:定义如下所示的存放学生信息的结构STUDENT,从键盘读入二 位学生信息,然后在屏幕上输出其中高分学生的信息。 struct STUDENT { char id[6];/学号 char name[2o];//姓名 int score;/成绩 : 2、编写程序实现功能:定义如下所示的存放学生信息的结构STUDENT,从键盘读入二 位学生信息,然后在屏幕上输出其中学号较大者的学生信息。 struct STUDENT char id[6];/学号 char name[2o];//姓名 int score;/成绩 ;
A. st[1].month B. st[1].birth.day C. st[0].id D. st[0].birth 14、(多选)若有如下变量 st 的声明,则下面正确访问变量 st 成员的方法有( )。 struct STUDENT { char id[10]; char name[20]; int age; float score; char sex; }st[10]; A. st.id[0] B. st[0].id C. st[0].id[0] D. st[0].id[10] 二、编程题 1、编写程序实现功能:定义如下所示的存放学生信息的结构 STUDENT,从键盘读入二 位学生信息,然后在屏幕上输出其中高分学生的信息。 struct STUDENT { char id[6]; //学号 char name[20]; //姓名 int score; //成绩 }; 2、编写程序实现功能:定义如下所示的存放学生信息的结构 STUDENT,从键盘读入二 位学生信息,然后在屏幕上输出其中学号较大者的学生信息。 struct STUDENT { char id[6]; //学号 char name[20]; //姓名 int score; //成绩 };

3、编写程序实现功能:定义如下所示的存放学生信息的结构STUDENT,从键盘读入二 位学生的信息,然后在屏幕上输出其中年龄较小者学生信息。 struct STUDENT { char id[6]:/学号 char name[2o]:/姓名 struct Tbirth { int year;/年 int month;/月 }birth;/出生年月 ; 4、编写程序实现功能:从当前盘当前目录下名为“STUDENT.TXT”的学生信息库文件中 (文件信息的格式如下),统计女生的人数,将统计结果显示在屏幕上。 10001 Rose F 10002 Jone M 10003Mi1kM 5、编写程序实现功能:从当前盘当前目录下名为“STUDENT.TXT”的学生信息库文件中 (文件信息的格式如下),查找出数学、语文两门课程成绩均及格的所有学生记录(设记录 数不超过10条),将查找结果依次显示在屏幕上。(注:成绩不小于60为及格) 10001Rose78.588.5 10002Jone65.060.5 10003Mi1k59.560.0
3、编写程序实现功能:定义如下所示的存放学生信息的结构 STUDENT,从键盘读入二 位学生的信息,然后在屏幕上输出其中年龄较小者学生信息。 struct STUDENT { char id[6]; //学号 char name[20]; //姓名 struct Tbirth { int year; //年 int month; //月 }birth; //出生年月 }; 4、编写程序实现功能:从当前盘当前目录下名为“STUDENT.TXT”的学生信息库文件中 (文件信息的格式如下),统计女生的人数,将统计结果显示在屏幕上。 10001 Rose F 10002 Jone M 10003 Milk M 5、编写程序实现功能:从当前盘当前目录下名为“STUDENT.TXT”的学生信息库文件中 (文件信息的格式如下),查找出数学、语文两门课程成绩均及格的所有学生记录(设记录 数不超过 10 条),将查找结果依次显示在屏幕上。(注:成绩不小于 60 为及格) 10001 Rose 78.5 88.5 10002 Jone 65.0 60.5 10003 Milk 59.5 60.0