题库 题库

【简答题】

请使用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<<”办公室房间号:”<<AU_OFFICE.THEROOMNO()<<ENDL
<<”办公室长度:”<<<endl
<<”办公室宽度:”<<<endl
<<”办公室面积:”<<<endl
<<”办公室所属部门:”<<ALL—OFFICE.THEDEPARTMENT()<
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,”会汁科”)

相关试题

单选题 下列数据结构中,属于非线性结构的是( )。 查看答案
单选题 程序流程图中带有箭头的线段表示的是( )。 查看答案
单选题 软件详细设计产生的图如下:

该图是( )。
查看答案
单选题 必须用一对大括号括起来的程序段是( )。 查看答案
单选题 秘序调试的任务是( )。 查看答案
单选题 下列字符串中。不可以用做c++标识符的是(  )。 查看答案
单选题 软件按功能可以分为应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是( )。 查看答案
单选题 软件设计中模块划分应遵循的准则是( )。 查看答案
单选题 下列叙述中正确的是(  )。 查看答案
单选题 有如下程序:
#include
using namespace std;
class A{
public:
virtual void fancl(){cout<<”Al”;}
void func2(){cout<<”A2”;}
};
class B:public A{
public:
void funcI(){tout<<”Bl”;}
void func2(){tout<<”B2”;}
};
intmain()}
A*P=new B:
P—>funcl();
P—>func2();
delete p;
return 0;
}
执行这个程序的输出结果是(  )。
查看答案
单选题 不能作为重载函数的调用的依据是(  )。 查看答案
单选题 如果类A被说明成类B的友元,则( )。 查看答案
单选题 有如下类定义:
class Foo
{
public:
Foo(int v):value(V){}//①
~Foo(){}//②
private:
Foo(){}//③
int value=0://④
};
其中存在语法错误的行是(  )。
查看答案
单选题 下列程序的执行结果为( )。
#include
void main()
{
int a=3,b=0;
int*P =&a;
b=+a++;
cout<<*P<<”,”<<B<
}
查看答案
单选题 下面关于break语句的描述中,不正确的是( )。 查看答案
单选题 下面程序的运行结果为( )。
#include
void main()
{
for(int a=0,x=0;!x&&a<=10;a++)
{
a++:
}
cout<<A<
}
查看答案
单选题 有如下程序:
#inClude using namespaCe std; Class A{
publiC:
statiC int a;
void init(  ){。a=1;}
A(int a=2){init(  );a++;} };
int A::a:0: A obj;
int main(  ) {
Cout<<OBJ.A:&NBSP;&NBSP;&NBSP;
}
运行时输出的结果是(  )。
查看答案
单选题 下列运算符中,在c++语言中不能重载的是( )。 查看答案
单选题 有如下程序:
#inClude using namespaCe std; Class Base{
publiC:
void output(){Cout<<1;}
virtual void Print(){Cout<<'B’;} };
Class Derived:publiC Base{ publiC:
void output(){Cout<<2;} void Print(){Cout<<’D ';} };
int main() {
Base * ptr=new Derived; ptr一>output();
ptr一>Print(); delete ptr;
retum0; }
执行这个程序的输出结果是( )。
查看答案
单选题 执行下列语句段后,输出字符“*”的个数是( )。
for(int i=50;i>1;i-=2)Cout<<'*':
查看答案