题目内容:
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类0ffice的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 办公室房间号:308
办公室长度:5.6
办公室宽度:4.8
办公室面积:26.88
办公室所属部门:会计科
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“///料料found••料”。
#include<isotream>
using namespaee std;
class Room{ //“房间”类
int room_n0;//房间号
double length;//房间长度(m)
double width;//房间宽度(n1)
public:
Room(int the—room—n0,double the~length,double the—width):loom—no(the—room—no),length(the—
length),width(the—width){}
int theRoomNo()eonst{return iDonl—n0;}
//返回房间号
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_n0,double the_length,double the_width,eonst 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<<”办公室房间号:”<<au_office.theRoomNo()<<endl
<<”办公室长度:”<<an office.theLength()<<endl
<<”办公室宽度:”<<an 0ffice.theWidth()<<endl
<<”办公室面积:”<<an office.theArea()<<endl
<<”办公室所属部门:”<<all—office.theDepartment()<<endl;
return 0;
}
参考答案:【答案仅供学习,请勿对照自行用药等】
答案解析: