首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”
admin
2020-07-23
26
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
办公室房间号:308
办公室长度:5.6
办公室宽度:4.8
办公室面积:26.88
办公室所属部门:会计科
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include<iostream>
using namespaee std;
class Room{ //“房间”类
int room_no;//房间号
double length;//房间长度(m)
double width;//房间宽度(m)
public:
Room(int the_room_no,double the_length,double the_width):room_no(the_room_no),length(the_length),width(the_width){ }
int theRoomNo()const{return room_no;}
//返回房间号
double theLength()const{return length;} //返回房间长度
double theWidth()const{ return width;} //返回房间宽度
//**********found**********
double theArea()const{____________}//返回房间面积(矩形面积)
};
class Office:public Room{//“办公室”类
char * depart;//所属部门
public:
Office(int the_room_no,double the_length,double the_width,const char * the_depart)
//**********found**********
:_________________{
depart=new char[strlen(the_depart)+1];
//**********found**********
strcpy(_______________);
}
~Office(){delete[]depart;}
const char * theDepartment()const{return depart;}//返回所属部门
};
int main(){
//**********found**********
Office__________;
cout<<"办公室房间号:"<<an_office.theRoomNo()<<end1
<<"办公室长度:"<<an_office.theLength()<<end1
<<"办公室宽度:"<<an_office.theWidth()<<end1
<<"办公室面积:"<<an_office.theArea()<<end1
<<"办公室所属部门:"<<an_office.theDepartment()<<end1;
return 0;
}
选项
答案
(1)return length * width; (2)Room(the_room_no,the_length,the_width) (3)depart,the_depart (4)an_office(308,5.6,4.8,"会计科")
解析
(1)主要考查考生对成员函数的掌握,题目要求返回房间面积(矩形面积)。由此可知空格部分要填写的是一个return语句,返回房间面积,也就是length * width,因此可以得出程序:return length * width;。
(2)主要考查考生对派生类的构造函数的掌握,派生类的构造函数要使用成员列表初始法先对基类进行初始化。
(3)考查strcpy函数,由前一条语句“depart=newchar[strlen(the_depart)+1];”可知,程序给depart分配了长度为the_depart串长加1的空间,因此要复制字符串the_depart串到depart,直接填写“strcpy(depart,the_depart)”即可。
(4)主要考查考生对类的掌握,题目要求输出的结果为:
办公室房间号:308
办公室长度:5.6
办公室宽度:4.8
办公室面积:26.88
办公室所属部门:会计科
由Office类的构造函数可知要定义的一个Office类的对象为an_office(308,5.6,4.8,"会计科")。
转载请注明原文地址:https://jikaoti.com/ti/vql0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面描述中错误的是( )。
关于函数重载,下列叙述中错误的是()。
在一个程序文件中有如下语句:externintvar;关于这个语句,下列表述中错误的是
有如下程序:#includeusingnamespacestd;classCC{intk;public:CC(intn):k(n){}
设c1和c2是类MyClass的对象,若将运算符"+"和"*"作为类MyClass的成员函数重载,则表达式c1+c2*c1等价于
若有下面的函数调用:fun(a+b,3,max(n-1,b))则fun的实参个数是()。
软件生命周期可分为定义阶段、开发阶段和维护阶段,下面不属于开发阶段任务的是
设c1和c2是类MyClass的对象,若将运算符"+"和"*"作为类MyClass的成员函数重载,则表达式c1+c2*c1等价于
下列运算符只能重载为成员函数的一组是
下列关于输入流类成员函数getline()的表述中,错误的是
随机试题
影响地产价格的经济因素包括()
【B1】【B3】
下列除哪一项外,均属参苓白术散的主治证候( )
肺脂肪栓塞的病变特征是
A.视神经病变B.视束病变C.视交叉两外侧部分病变D.视放射部分病变E.枕叶病变同侧全盲是
不经胰蛋白酶激活的胰酶是()。
甲省乙市工商管理局对出售盗版光盘的个体工商户丙处以罚款,如丙不服,()申请行政复议。
狭义上的货运事故是指运输中发生的货损货差事故,广义上的货运事故还可以包括运输单证差错、迟延交付货物、海运中的“无单放货”等情况。下列()不属于货运事故。
某企业本期应交房产税税额6万元,应交土地使用税税额6万元,印花税税额3万元,耕地占用税税额30万元,契税税额15万元,车辆购置税税额2.4万元。则本期影响应交税费科目的金额是()万元。
TherearemanywetlandsinChinaandsomeofthemhavebecometheworld’simportantwetlands.TheChineseYellowSeaWetlandsar
最新回复
(
0
)