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

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

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

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

基本操作题

1.请打开考生文件夹下的解决方案文件proj1,该工程中包含程序文件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<iostream>

using namespace std;

c1ass 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/3600)%24),days(i/8 6400){}

void Clock::set(unsigned long i)

{

total_sec=i;

seconds=i%60;

minutes=(i/60)%60;

hours:(i/3600)%60;

days=i/86400;

}

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

void Clock::print()

{

cout <<days << \\

(1)void Clock::print()cons!

(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.请打开考生文件夹下的解决方案文件proj2,此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类Office的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:

办公室房间号:308

办公室长度:5.6

办公室宽度:4.8

办公室面积:26.88

办公室所属部门:会计科

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

#include<iostream>

using namespace std;

class Room{ //“房间”类

int room no; //房间号

double length;//房间长度(m)

double width; //房间宽度(m)

public:

Room(int the_room no,double the_length,double the_width):room_no(the_room _no),length(the_length),width(the_width){}

int theRoomNo()const { return room_no}

//返回房间号

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_no,double the_length,double the_width,const char * the_depart)

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

:_____________{

depart=new char [ strlen(the_depart)+1];

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

strcpy(_________);

}

~Office(){delete[]depart;}

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

};

int main(){

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

Office___________;

cout<<\\

(1)return length * width;

(2)Room(the_room_no,the_length,the_width)

(3)depart,the_depart

(4)an_office(308,5.6,4.8,”会计科”)

解析:(1)主要考查考生对成员函数的掌握,题目要求返回房间面积(矩形面积)。由此可知空格部分要填写的是一个return语句,返回房间面积,也就是length*width,因此可以得出程序return length * width;。

(2)主要考查考生对派生类的构

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

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

推荐资源

客服

扫码添加客服微信

热线

官方客服

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

电话客服:

客服微信:pujinet

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

公众号

扫码关注微信公众号