2020年计算机二级《C++》考前应用试题
三、简单应用题
42请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类0ffice的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的准确输出结果应为: 办公室房间号:308 办公室长度:5.6 办公室宽度:4.8 办公室面积:26.88 办公室所属部门:会计科
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“///料料found料”。 #include
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<<”办公室房间号:”< <<”办公室长度:”< <<”办公室宽度:”< <<”办公室面积:”< <<”办公室所属部门:”< return 0; }
参考解析:
(1)returtl length*width;
(2)Room(the_room_no,the_lengih,the_width) (3)depart,the_depart
(4)an_office(308,5.6,4.8,”会汁科”) 四、综合应用题
43请使用VC6或使用【答题】菜单打开考生目录proj3下的工程文件proj3,此工程中包含一个源程序文件proj3.cpp,补充编制c++
2020年计算机二级《C++》考前应用试题



