首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”
admin
2018-03-13
18
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
办公室房间号:308
办公室长度:5.6
办公室宽度:4.8
办公室面积:26.88
办公室所属部门:会计科
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****
found****”。
#inclUde
using namespace 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<<"办公室房间号:"<
<<"办公室长度:"<
<<"办公室宽度:"<
<<"办公室面积:"<
<<"办公室所属部门:"<
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=new char[strlen(the_depart)+1];可知,程序给depart分配了长度为the_depart串长加l的空间,因此要复制字符串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://kaotiyun.com/show/8VAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下类定义中可能会引起错误的语句是classA{public:~A(){}//1inti;//2private:intj;//3
有如下程序:#include"iostream.h"voidmain(){intx=1,a=0,b=0;swish(X){case0:b++;case1:a++;case
在面向对象方法中,属性与操作相似的一组对象称为______。
有如下函数模板定义:template<classT>Tfunc(Tx,Ty){returnx*x*y*y;)在下列对func的调用中,错误的是
定义如下枚举类型:enum{Monday,Tuesday,Wednesday,Thrusday,Friday=2};则下列语句正确的是
结构化程序设计的主要特点是
在下面程序的横线处填上适当的内容,使程序执行后的输出结果为ABCD。#include<iostream.h>usingnamespacestd;classA{pu
随机试题
下列代谢过程不能直接补充血糖的是
A.四逆散B.四逆汤C.当归四逆汤D.小建中汤E.理中丸治疗血虚寒厥证应选择的方剂是
画有“传丝公主”画像的木版画发现于()。
在新课程中,教师的角色发生了变化,下列说法不正确的是()。
违反治安管理行为事实清楚,证据确凿,可以当场作出治安管理处罚决定的有()。
刘秀采取了哪些措施来增加皇权?
《马太受难乐》
A、条件(1)充分,但条件(2)不充分B、条件(2)充分,但条件(1)不充分C、条件(1)和条件(2)单独都不充分,但条件(1)和条件(2)联合起来充分D、条件(1)充分,条件(2)也充分E、条件(1)和条件(2)单独都不充分,条件(1)和条件(2
SupposeyourfriendDavidjustbrokeupwithhisgirlfriendandwasfeelingsad.Writehimanemailto1)comforthim,and
以下名称是手机中的常用软件,属于系统软件的是()。
最新回复
(
0
)