报名 百分网手机站

计算机二级《C++》上级考试试题及答案

时间:2020-11-02 08:29:37 报名 我要投稿

计算机二级《C++》上级考试试题及答案2017

  一、基本操作题

计算机二级《C++》上级考试试题及答案2017

  1请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl。程序中位于每个“//ERROR****found料****之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:

  Name:Smith Age:21 ID:99999 CourseNum:12

  Record:970

  注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。

  #include

  using namespace std;

  class Studentlnfo

  {

  protected:

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

  char Name;

  int Age;

  int ID:

  int CourseNum;

  float Record;

  public:

  Studentlnfo(char*name,int Age,int ID,int coumeNum,float record);

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

  void~Studentlnfo(){}

  float AverageRecord(){

  return Record/CourseNum;

  }

  void show()const{

  cout<<”Name:”<

  <<”CourseNum:”<

  }

  };

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

  StudentInfo StudentInfo(char*Name,int Age,int ID,int CourseNum,float Record)

  {

  Name=name;

  Age=age;

  this一>ID=ID:

  CourseNum=courseNum:

  Record=record;

  }

  int main()

  {

  Studentlnfo st(’’Smith”,21,99999,12,970);

  st.show();

  return 0;

  }

  参考解析:

  (1)char*Name;

  (2)~Studentlnfo(){}

  (3)Studentlnf0::Studentlnfo(char*name,int age,,int ID,int eourseNum,float record)

  二、简单应用题

  2请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:

  80

  150

  100

  1

  注意:只能在横线处填写适当的.代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。

  #include

  class vehicle

  {

  private:

  int MaxSpeed;

  int Weight;

  public:

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

  vehicle(int maxspeed,int weight):——

  ~vehicle(){};

  int getMaxSpeed(){return MaxSpeed;}

  int getWeight(){retum Weight;}

  };

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

  class bicycle:——public vehicle

  {

  private:

  int Height;

  public:

  bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){}

  int getHeight(){retum Height;};

  };

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

  class motorcar:——public vehicle

  {

  private:

  int SeatNum;

  public:

  motorcar(int maxspeed。int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum){}

  int getSeatNum(){return SeatNum;};

  };

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

  class motorcycle:——

  {

  public:

  motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,

  height),motorcar(maxspeed,weight,1){}

  };

  void main()

  {

  motorcycle a(80,150,100);

  cout<

  cout<

  cout<

  cout<

  }

  参考解析:

  (1)MaxSpeed(maxspeed),Weight(weight){f;

  (2)virtual

  (3)virtua1

  (4)public bicycle,public motorcar


更多计算机二级C++相关试题分享:

1.2017年3月计算机二级C++考前练习题及答案

2.2017计算机二级C++模拟题及答案

4.2017年3月计算机二级C++练习题及答案

5.2017计算机二级C++基础习题及答案

6.2017计算机二级C++考点习题及答案

7.2017年12月计算机二级C++考前练习题及答案

8.2017计算机二级C++强化习题及答案

9.2017计算机二级C++强化习题及答案

10.计算机二级考试C++练习及答案