首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程
admin
2018-03-13
25
问题
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两个人的教室也同时得到改变。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:
改换教室前:
学号:0789 姓名:张三 班级:062113 教室:521
学号:0513 姓名:李四 班级:062113 教室:521
改换教室后:
学号:0789 姓名:张三 班级:062113 教室:311
学号:0513 姓名:李四 班级:062113 教室:311
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。
#include
using namespace std;
class Class{ //“班级”类
public:
Class(const char*id,const char*room){
strcpy(class id,id);
//*********found*********
}
const char*getClassID()
const{return class id;} //
返回班号
//*********found*********
const char *getClassroom()
const{_________} //返回所在教室房号
void changeRoomTo(const char
*new room) { //改换到另一个指定房号的教室
strcpy(classroom,new_room);
}
private:
char class id[20]; //班号
char classroom[20]; //所在教室房号
};
class Student{ //“学生”类
char my id[10]; //学号
char my name[20];//姓名
Class&my class; //所在教室
public:
//**********found**********
Student(const char*the_id,const char*the_name,Class&the class):__________{
strcpy(my_id,the_id);
strcpy(my_name,the_name);
}
const char*getID()const{return my_id;}
const char*getName()const{return my_name;}
Class getClass()const{return my_class;}
};
void shOwStudent (Student * stu){
cout<<"学号:"<
getID()
<<" ";
cout<<"姓名:"<
getName()
<<" ";
cout<<"班级:"<
get Class().getClassID()<<" ";
cout<<"教室:"<
get Class().getClassr00m() <
}
int main(){
Class cla("062113","521");
Student Zhang("0789","张三",cla),Li("0513","李四",cla);
cout<<"改换教室前:"<
showStudent(&Zhang);
showStudent(&Li);
//062113班的教室由521改换到311
//**********found**********
cout<<"改换教室后:"<
showStudent(&Zhang);
showStudent(&Li);
return 0;
}
选项
答案
(1)strcpy(classroom,room); (2)return classroom; (3)my_class(the_class) (4)cla.changeRoomTo("311");
解析
(1)主要考查考生对strcpy函数的掌握情况,根据上一条语句:strcpy(classjd,id);可知,这条语句要复制字符串room,因此使用strcpy函数复制,即strcpy(classroom,room);。
(2)主要考查考生对函数返回值的掌握情况,根据函数要求:返回所在教室房号及函数要求返回的类型为const char*,可以得出这里直接使用return语句返回classroom即可。
(3)主要考查考生对构造函数的掌握情况,先看函数体中:
strcpy(my_id,the_id);
strcpy(my_name,the_name);
可知只有参数Class&the_class未使用,因此在这里使用成员列表初始化给my_class赋初始值。
(4)主要考查考生对成员函数调用的掌握,程序要求062113班的教室由521改换到311。在类Class中已经定义了函数:void changeRoomTo(const char*new_room),因此直接调用函数changeRoomTo即可。
转载请注明原文地址:https://jikaoti.com/ti/2Lt0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面程序的输出是:***********5.235.23***********请将下划线上遗漏的部分补充完整。#include<iostream>#include<iom
在进行任何C++流的操作后,都可以用C++流的有关成员函数检测流的状态;其中只能用于检测输入流状态的操作函数名称是
有如下程序:#include<iostream.h>usingnamespacestd;classBase{protected:inti:public:intj;
定义如下枚举类型:enum{Monday,Tuesday,Wednesday,Thrusday,Friday=2};则下列语句正确的是
执行语句序列intn:cin>>n:switch(n){case1:case2:cout<<’1’;case3:case4:cout<<’2’:break;
结构化程序设计的主要特点是
对建立良好的程序设计风格,下面描述正确的是
下列程序的输出结果为2,请将程序补充完整。#include<iostream>usingnamespacestd;classBase{public:______voidfun(){cout<<1;}
软件生命周期包括8个阶段。为了使各时期的任务更明确,又可分为3个时期:软件定义期、软件开发期、软件维护期。编码和测试属于______期。
随机试题
原子吸收法是根据基态原子和激发态原子对特征波长吸收而建立起来的分析方法。()
A.医生为患者做检查时,由于消毒观念不强造成交叉感染B.医生的行为使某个患者受益,但却损害了别的患者的利益C.医生对患者的呼叫或提问给予应答D.妊娠危及孕妇的生命时,医生给予引产E.医生泄露患者的个人隐私上述各项中属于医生违背尊重原则的是
用于控制支气管哮喘急性发作的药物是
来源于豆科且含黄酮类成分的药材有
下列说法错误的是( )。
有时候我们会高估自己低估别人.有的时候我们会以自己的眼光看待别人,有时候面对重大事件会存在侥幸心理,你存在这种情况吗?你怎么解决的?
政府的功能是满足人民群众的真正需要,除非政府知道那些需要是什么,否则政府就无法满足那些需要,言论自由能确保政府官员听到这样的需求信息,因此,对一个健康的国家来说,言论自由是必不可少的。下面哪一项如果为真,不能削弱上述论证?
请在“答题”菜单下选择“演示文稿”命令,然后按照题目要求再打开相应的命令,完成下面的内容,具体要求如下:注意:下面出现的所有文件都必须保存在考生文件夹下。打开考生文件夹下的演示文稿yswg.pptx,按照下列要求完成对此文稿的修饰并保存。
Inthepast,theParkServicefocusedonmakingthebigscenicparksmore【21】______andcomfortablefortourists.Roadswere
TheSantaAnaappealscourtupheldanearlierjuryverdictawarding$3.2millionindamagestoAlexisSartiwhosufferedserio
最新回复
(
0
)