首页 > 全部 > 二级C++ > 国家二级C++机试(操作题)模拟试卷305

国家二级C++机试(操作题)模拟试卷305

本单篇文档共3989字,内容预览3600字,预览为有答案版,源文件无水印,下载后包含无答案空白卷版和有答案版,同时也有计算机类NCRE全国计算机二级整科真题模拟题,讲义课件,思维导图,易错高频题等下载。
二级C++ 章节练习 6539人下载
价格: 0.80 原价:¥8.00
收藏

国家二级C++机试(操作题)模拟试卷305

基本操作题

1.使用VC6打开考生文件夹proj1下的工程proj1,其中有“沙发”类Sofa和主函数main的定义。程序中位于每个//ERROR **********found**********下的语句行有错误,请加以更正。更正后程序的输出应该是:

座位数:3

颜色:红色

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

#include<iost:ream>

using namespace st:d;

class Sofa{ //“沙发”类

int seats; //座位数

char color[10];//颜色

public:

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

Sofa(int s,const char * co)

{

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

if(CO=NULL)

color[0]=’\0’;

else

strcpy(color,co);

}

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

const char * getSeats()const{return seats;)

const char * gel:Color()const{return color;)

};

int:main(){

Sofa sara(3);

cout:<<“座位数:”<<sara.getSeats()<<end1;

cout:<<“颜色:”<<sara.getColor()<<end1;

return 0;

}

(1)Sofa(int s,const char * co=“红色”):seats(s){

(2)if(co==NULL)

(3)int getSeats()const{return seats;}

解析:

简单应用题

2.使用VC6打开考生文件夹proj2下的工程proj2,其中有元素类Element和队列类Queue的定义。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的输出结果应为:

3 8 5 0

5 0 7

注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。

#include<iostream>

#include<cmath>

#include<cstdlib>

using namespace std;

#define MaxLength 100

class Element:{ //“元素”类

public:

int n;

Element:(int i=0):n(i){}

};

class Queue{ //“队列”类

Element * element;

//指向存储元素的数组的指针

int tail;//队尾元素的下标

public:

Queue():element(new Elemerit;[100]),tail(-1){}

~Queue(){delete[]element;}

void push(Element ele);

//在队列尾端添加一个元素

Element pop();

//在队列首端删除一个元素,返回被删元素

Element ffont()const{Eeturn element:[0];}

//返回队首元素,但不从队列中删除该元素//******found******

int size()const{return(_______);} //返回元素个数

void show()const;

//显示集合中所有元素

};

void Queue∷push (Elementele){

if(tail==HaxLength-1)

return;//空间满,不做任何处理

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

_______;

}

Element Queue∷pop(){

if(size()==0)exit(1);

//队列空,不做任何处理

Element tmp=element[0];

for(int i=0;i<tail;i++)

element[i]=element[i+1];

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

_______;

return trnp;

}

void Queue∷show()COnst{

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

for(_______)

cout<<element[i].n<<’ ’;

cout<<end1;

}

int main(){

Queue q;

q.push(3);

q.push(8);

q.push(5);

q.push(0);

q.show();

q.pop();

q.pop();

q.push(7);

q.show();

return 0;

}

(1)tail+1

(2)element[++tail]=ele

(3)tail--

(4)int i=0;i<=tail;i++

解析:

综合应用题

3.使用Vc6打开考生文件夹proj3下的工程proj3,其中声明了NyString类,它是一个用于表示字符串的类。成员函数reverse将字符串反转,例如“abode”反转后就成了“edcba”。请补充完整函数reverse。在main函数中给出了一个测试数据,此情况下程序的输出应该是:

This is a string

gnirtS a si sihT

注意:只需在函数reverse的//********333********和//********666********之间填入若干语句,不要改动程序中的其他内容。

//NyString.h

#include<iostream>

usirig namespace std;

char * dup(const char *);<

本文档预览:3600字符,共3989字符,源文件无水印,下载后包含无答案版和有答案版,查看完整word版点下载

剩余未完,查看全文
收藏
国家二级C++机试(操作题)模拟试卷305

推荐资源

客服

扫码添加客服微信

热线

官方客服

如遇问题,请联系客服为您解决

电话客服:

客服微信:pujinet

工作时间:9:00-18:00,节假日休息

公众号

扫码关注微信公众号