计算机学历 百分网手机站

计算机二级《C++》预测试题(5)

时间:2017-12-11 19:27:13 计算机学历 我要投稿

2017年计算机二级《C++》预测试题

  Const Char * 9etName()Const{return*finin9;} Const Char * 9etColorString()Const{

  switCh(Color){

  Case BLACK:return”blaCk“; Case WHITE:return”white”:

  Case YELLOW:return’"yellow”: Case BROWN:return”brown”; ease PIEBALD:return”piebald”:

  }

  return”motley”;

  }

  void show()Const{ . Cout<<”There is a”<

  } }; int main(){

  //ERROR**********found**********

  Dog dogl(”Hoh0”,WHITE),dog2(”Haha”,BLACK);d0g3(”Hihi”,0THER); d091.show();

  dos2.show(); dos3.show(); return 0;

  }

  参考解析:

  (1)this->color=color:

  (2)consL char getName()eonst{return*name;}

  (3)Dog dogl(”Hoho”,WHITE)。dog2(”Haha”,

  BLACK),dog3(”Hihi”,OTHER);

  三、简单应用题

  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(){[]depart;}

  const char*theDepartment()const{return depart;}//返回所属部门

  };

  int main(){

  //**********found**********

  Office_______________;

  cout<<”办公室房间号:”<

  <<”办公室长度:”<

  <<”办公室宽度:”<

  <<”办公室面积:”<

  <<”办公室所属部门:”<

  return 0;

  }

 

【2017年计算机二级《C++》预测试题】相关文章:

1.2017年计算机二级C++模拟试题

2.2017年计算机二级C++考试试题

3.2017年计算机二级C++考试试题

4.2017年计算机二级MS office预测试题及答案

5.2017年计算机二级《MSOffice》预测试题(带答案)

6.2016年计算机二级C++笔试试题

7.2016年计算机二级考试C++试题及答案

8.2016年计算机二级考试C++试题及答案