软题库 学习课程
当前位置:信管网 >> 在线考试中心 >> 试题查看
试题题型【分析简答题】
试题内容

试题五(共15分)
阅读以下说明、图和C++代码,填补C++代码中的空缺(1)—(5),将解答写在答题纸的对应栏内。
【说明】
已知某公司主要有两大类耗电资产(Asset):计算机(ComputerAsset)和建筑物(BuildingAsset)。为了节约能源,通过控制各种电源,将可关闭的房灯、计算机显示器等在夜间关闭。
为了实现上述需求,设计了如下图所示的类图,并用下面的C++代码加以实现。

【C++代码】
#include
#include
using  namespace  std;
class Asset{             /*通用资产,基类*/
public: virtual ~Asset( ){ };
};
class PowerSwitchable{                  /*抽象基类,可在夜间关闭电源的物体接口*/
public: virtual void powerDown( )=0;      /*powerDown( )函数接口*/
virtual void powerUP( )=0;        /*powerUp函数接口*/
};
class computerAsset: public Asset{      /*计算机资产*/
protected: int deskNumber;
public:
ComputerAsset(int desNumber){   this->deskNumber= deskNumber;
};
class ComputerCPU  (1)  {     /*计算机主机,永不关闭*/
public:
ComputerCPU(int desNumber): ComputerAsset (deskNumber){ }
};
class ComputerMonitor (2){    /*计算机显示器*/
public:
ComputerMonitor(int roomNumber):ComputerAsset(roomNumber),
PowerSwitchable( ){ }
~ComputerMonitor ( ){ }
void powerDown( ) {        /*关电源,代码略*/         }
void powerUp( ) {             /*开电源,代码略*/        }
};
/*BuildingAsset、BuildingLight、EmergencyLight和RoomLights代码省*/
class BuldingManagement  {
private:
Asset* things[24];   int numItems;
public:
void goodNight( ){           /*值班员定时“关闭”时调用,关闭可关闭的电源*/
for(int i=0;i(3)   ps=dynamic_cast(things[i]);
if(ps!=0)
ps->powerDown();
}
}
/*goodMorning( )与goodNight( )类似,依次调用powerUp( ),实现省*/
void add(Asset*thing){                /*为建筑添加资产*/
things[(4)]=thing;
}
};
int main(){
BuildingManagement* b1=(5) BuildingManagement( );
b1->add(new RoomLights(101));            //101房间的控制灯
b1->add(new EmergencyLight(101));         //101房间的应急灯
b1->add(new ComputerCPU(10104));        //101房间4号桌上的计算机
b1->add(new ComputerMonitor(10104));      //101房间4号桌上的计算机显示器
b1->goodNight( );
delete b1;
}

查看答案

相关试题