首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件mmn.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件mmn.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序
admin
2015-06-27
42
问题
请使用VC6或使用【答题】菜单打开考生文件夹prog2下的工程prog2,此工程中包含一个程序文件mmn.cpp,其中有“班级”类Class和“学生”类Student的定义,还有主函数main的定义。在主函数中定义了两个“学生”对象,他们属于同一班级。程序展示,当该班级换教室后,这两个人的教室也同时得到改变。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:
改换教室前:
学号:0789姓名:张三班级:062113教室:521
学号:0513姓名:李四班级:062113教室:521
改换教室后:
学号:0789姓名:张三班级:062113教室:311
学号:0513姓名:李四班级:062113教室:311
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。
#include
usingnamespacestd;
classClass(//“班级”类
public:
Class(constchar*id,constchar*
room){
strcpy(classid,id);
f}**********found**********
}
constchar*getClassID()const{returnclassid;}//返回班号
//**********found**********
constchar*getClassroom()const
{________}//返回所在教室房号
voidchangeRoomTo(constchar*new
room){//改换到另一个指定房号的教室
strcpy(classroom,new_room);
}
private:
charclassid[20];//班号
charclassroom[20];//所在教室房号
};
classStudent{//“学生”类
charmyid[10];//学号
charmyname[20];//姓名
Class&myclass;//所在教室
public:
//**********found**********
Student(constchar*theid,const
char*the_name,Class&the_class):
________;
strcpy(my_id,the_id);
strcpy(my_name,the_name);
}
constchar*getID()const{returnmy_id;}
constchar*getName()const{returnmy_name;}
ClassgetClass0const{returnmy_class;}
};
voidshowStudent(Student*stu){
cout<<"学号:"<
getID()<<"";
cout<<"姓名:"<
getName()<<"";
cout<<"班级:"<
getClass().
getClassID()<<"";
cout<<"教室:"<
getClass().
getClassroom()<
}
intmain(){
ClasScla("062113","521");
StudentZhang("0789","张三",cla),
Li("0513","李四",cla);
cout<<"改换教室前:"<
showStudent(&Zhang);
showStudent(&Li);
//062113班的教室由521改换到311
//**********found**********
cout<<--改换教室后:"<
showStudent(&Zhang);
showStudent(&Li);
return0;
}
选项
答案
(1)strcpy(classroom,room); (2)returnclassroom; (3)my_class(the_class) (4)cla.changeRoomTo("311");
解析
(1)主要考查考生对strcpy函数的掌握情况,根据上一条语句:strcpy(class_id,id);可知,这条语句要复制字符串room,因此使用strcpy函数复制,即strcpy(classroom,room);。
(2)主要考查考生对函数返回值的掌握情况,根据函数要求:返回所在教室房号及函数要求返回的类型为constchar*,可以得出这里直接使用return语句返回classroom即可。
(3)主要考查考生对构造函数的掌握情况,先看函数体中:
strcpy(my_id,the_id);
strcpy(my_name,the_name);
可知只有参数Class&the_class未使用,因此在这里使用成员列表初始化给my_class赋初始值。
(4)主要考查考生对成员函数调用的掌握,程序要求062113班的教室由521改换到311。在类Class中已经定义了函数:voidehangeRoomTo(constchar*new_room),因此直接调用函数changeRoomTo即可。
转载请注明原文地址:https://kaotiyun.com/show/21BD777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
简述遗传素质在人的身心发展中的作用。
教育的个体个性化功能主要体现在:它促进人的主体意识的发展,促进人的个体特征的发展,以及促进人的
以下不属于贷款风险五级分类管理中的类型的是()。
下列货币政策操作中,可以增加货币供给的是()。
公开市场操作
对于宪法的归属,甲、乙、丙三个同学有不同看法。甲认为:宪法是一个法律部门,它属于部门法。乙认为:宪法是法的渊源,它属于法的渊源之一。丙认为:宪法是一个规范性法律文件,它属于规范性法律文件的范围。请运用法理学的知识对这些观点加以分析。
在社会规范中,一般地说,既规定权利又规定义务的有()。
实体法与程序法的划分标准是()。
联系中国实际,试述法对社会主义市场经济的作用。要求:观点明确,说理充分,条理清晰,语言规范、流畅。
I=sgn(χ2-y2+2)dχdy其中sgnχ为符号函数.
随机试题
WhenJackcamein,I________dinnerwithmyparents.
女性,34岁,公务员。低热,左颈部淋巴结肿大,压痛。抗感染治疗无效,实验室检查白细胞在正常范围,血沉快。淋巴结穿刺活检病理诊断为组织细胞坏死性淋巴结炎。曾误诊为淋巴瘤化疗,其主要组织学改变可能为
男,32岁。因发热、食欲不振、肝区疼痛来诊。超声诊断为肝脓肿。若患者有腹胀、恶心、呕吐、腹泻症状,大便检查找到阿米巴滋养体。对其采取药物治疗,首选的药物是
吴某在经过A地时被A地国家税务局,以违反税收征收管理法有关规定为由,扣留人身24小时。经查明,王某在6年前确实有过违反税收征收管理法行为。吴某被解除人身扣留后,回住所地B市,吴某不服A地国家税务局的人身扣留欲向法院起诉。问题:
甲乙两公司依法签订了一份买卖合同,该合同执行国家定价。在乙公司逾期交货的情况下,该产品的价格该如何确定()
最新研究显示,所谓“好胆固醇”也许并非真的那么好。研究引用大量基因资料,发现俗称“好胆固醇”的高密度蛋白胆固醇(HDL)水平即使升高,对降低心脏病风险也不一定有帮助;与此同时,因遗传因素而有较高HDL水平的人士患心脏病的风险并不低于天生HDL水平较低的人士
“眉开眼笑”、“怒目而视”等词汇涉及的是
下列安全设备中,不能部署在网络出口的是()。
Inthepopularmind,theInternetistherealizationoftheglobalvillage,wheretheflowofinformationandideasisunimpeded
NewJerseySchoolDistrictEasesPressureonStudents,BaringanEthnicDivide[A]Thisfall,DavidAderhold,thechiefofa
最新回复
(
0
)