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

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

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

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

基本操作题

1.请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,该工程中包含程序文件main.cpp,其中有类Clock(“时钟”)的定义和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:

Initial times are

0 d:0 h:0 m:59 s

After one second times are

0 d:0 h:1 m:0 s

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

#include

using namespace std;

class Clock

{

public:

Clock(unsigned long i=0);

void set(unsigned long i=0);

void print()const;

void tick();//时间前进一秒

Clock operator++();

private:

unsigned long total_sec,seconds,

minutes ,hours, days;

};

Clock::Clock(unsigned long i)

:total sec(i),seconds(i%60),

minutes((i/60)%60),

hours((i/3 600)%24),

days(i/8 64 00){}

void Clock::set(unsigned long i)

{

total sec=i;

seconds=i%60;

minutes=(i/60)%60;

hours=(i/3600)%60;

days=i/864 00;

}

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

void Clock::print()

{

tout<<days<<”d:”<<hours<<

”h:”

<<minutes<<”m:”<<seconds

<<”s”<<endl;

}

void Clock::tick()

{

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

set(total sec++);

}

Clock Clock::operator++()

{

tick();

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

return th~s;

}

int main()

{

Clock ck(59);

tout << ”Initial timeS aEe” <<

endl;

ck.print();

++ck;

tout << ”After one second times

aEe”<<endl;

ck.print();

return 0;

}

(1)void Clock::print()const

(2)set(++total_sec);

(3)return*this:

解析:(1)主要考查考生对成员函数的掌握,由Clock类中对函数print的声明void print()const;可知,在定义print函数时少了const。

(2)主要考查考生对++操作的掌握,根据函数要求,时间要先前进一秒,再调用函数set,因此total_sec++应改为++total_sec。

(3)主要考查考生对this指针的掌握,函数要求返回值Clock,即返回一个类,而不是指针,因此使用*this。

简单应用题

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

3 8 5 0

5 0 7

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

#include

#include

#include

using namespace std;

#define MaxLength i 00

class Element { //“元素”类

public:

int n;

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

};

class Queue{ //“队列”类

Element * element;

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

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

public:

Queue():element(new Element

[100]),tail(一1){}

一Queue(){delete[]element;}

void push(Element ele); //在队列

尾端添加一个元素

Element pop();

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

Element front()const{return element[0];

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

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

int size()const{ return

(_______);}//返回元素个数

void show()const,

//显示集合中所有元素

};

void Queue::push(Element ele){

if(tail==MaxLength一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******

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

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

推荐资源

客服

扫码添加客服微信

热线

官方客服

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

电话客服:

客服微信:pujinet

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

公众号

扫码关注微信公众号