首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件main.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程
admin
2017-07-04
30
问题
请使用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*getClass ID()const{re-
turn 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{re
turn my_name;)
Class getClass 0const{return my_class;)
};
void showStudent(Student*Stu){
cout<<”学号:”<
getID()<<" ";
cout<<”姓名:”<
getName()<<" ";
cout<<”班级:”<
getClass().
getClassID()<<””;
cout<<“教室:”<
getClass().
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)retum classroom; (3)my_class(the_class) (4)cla.changeRoomTo(”311”):
解析
(1)主要考查考生对strcpy函数的掌握情况,根据上一条语句:strcpy(class_id,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://kaotiyun.com/show/GLAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
已知语句int m=10;则下列引用的表示中正确的是
为了避免嵌套的if...else语句的二义性,C++规定与else配对的是
两个或两个以上模块之间联系的紧密程度称为( )。
树L中,度为1、2、3、4、5和6的节点个数为6、4、3、3、5、1,则L中叶子的个数是【】。
阅读下面程序:#include<iomanip.h>intmain(){cout<<setfill(’*’)<<setw(8);cout<<setprecision(5)<<3.1
继承具有(),即当基类本身也是某一个类的派生类时,底层的派生类也会自动继承间接基类的成员。
下列格式化I/O的操作符中,()是设置域宽的。
对于重载的运算符>>,它是一个()。
以下选项中合法的用户标识符是
随机试题
党政分开,是指把党的领导和政府的领导从()区别开来。
系统压力提高有利于甲醇吸收二氧化碳气体。
于某,男性,74岁,农民,早晨在菜地拔草,起立时突然昏倒,幸家人在旁,扶坐地上,病人神志渐清,面色苍白,唇青,呼吸微弱,肢冷汗出,大便失禁,但额尚温,舌质淡,脉沉微。宜选用方
农村土地调查记录表共有9栏,字母T应该填写的栏目是()。
对报关员行为规则的表述中,正确的是:
简述编写学习目标的基本要素(ABCD模式)。
(山西政法2009—88)12,20,16,18,17,()
“曲高和寡”出自战国宋玉的《对楚王问》,这一成语的本义是曲调高深,能跟着唱的人很少,多指知音难得。引申义是言论或作品不通俗,能了解的人很少。如果从经济学的角度来理解,它所体现出的道理是:
“在加强法治的同时。也要注意不能夸大法律的作用。”请分析之。
Dayafterday,asmallbluetruckspeedsalongtheroadsofDenmark’sislandofFunen.Abigdarkdogsitsbesidethedriver,lo
最新回复
(
0
)