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

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

一、基本操作题

41d70fe9446f585b3c84c904965a40df.png

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<

<

}

};

//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++相关试题分享:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值