[计算机类试卷]国家二级C++机试(操作题)模拟试卷346及答案与解析.doc

上传人:appealoxygen216 文档编号:497428 上传时间:2018-11-28 格式:DOC 页数:9 大小:39.50KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷346及答案与解析.doc_第1页
第1页 / 共9页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷346及答案与解析.doc_第2页
第2页 / 共9页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷346及答案与解析.doc_第3页
第3页 / 共9页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷346及答案与解析.doc_第4页
第4页 / 共9页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷346及答案与解析.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

1、国家二级 C+机试(操作题)模拟试卷 346及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,该工程中包含程序文件 main cpp,其中有类 Door(“门 ”)和主函数 main的定义。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 打开 503号门 门是锁着的,打不开。 打开 503号门的锁 锁开了。 打开 503号门 门打开了。 打开 503号门 门是 开着的,无须再开门。 锁上 503号门 先关门 门锁上了。 注意:只修改每个 “ ERROR*found*” 下

2、的那一行,不要改动程序中的其他内容。 #include using namespace std; class Door int num; 门号 bool closed; true表示门关着 bool locked; true表示门锁着 public: Door(int num) ERROR*found* num=thiS-num; closed=locked=true; bool isClosed()const return closed; 门关着时返回 true,否则返回 false bool isOpened()constreturn! closed; ) 门开着时返回 true,否则返回

3、 false bool iSLocked()const return locked; ) 门锁着时返回 true,否则 返回 false bool isUnlocked()conStreturn ! locked; ) 门未锁时返回 true,否则返回 false void open() 开门 cout #include using namespaoe std; 平面坐标中的点 本题坐标系统中, x轴的正方向水平向右, y 轴的正方向竖直向下。 class Point: public: Point(double X=0 0, double y=0 0): x一 (x), y一 (y) doub

4、le getX()constreturn x_; ) double getY()constreturn y_; ) void setX(double x)x_=x; ) void setY(double y)y_=y; ) private: double x_; x坐标 double y_; y坐标 ; /矩形 class Rectangle public: Rectangle(Point P, int w, int h) : point(p), width(w), height(h) double area()const矩形面积 return width*height; Point topL

5、eft()const左上角顶点 return point; Point bottomRight()const 右下角顶点 (注: Y轴正方向竖直向下 ) *found* return Point(_); private: Point point;左上角顶点 double width;水平边 长度 double height;垂直边长度 ; /圆形 class Circle public: Circle(Point P, double r): center (p), radius(r) Rectangle boundingBox()const; 外切矩形 double area()const圆形

6、面积 *found* return PI*_; public: static const double PI;圆周率 private: Point center; 圆心 double radius; 半径 ; const double Circle: PI=3 14159; Rectangle Circle: boundingBOx ()const *found* Point pt(_); int w, h; *found* W=h=_; return Rectangle(pt, W, h); int main() Point P(3, 2); Circle c(p, 1); coutnum=

7、nun; (2)if(!closed) (3)void lock() 【试题解析】 (1)主要考查考生对 this指针的掌握,在构造函数中 this指针指向的是当前类,因此要给 num赋值使用语句 this一 num=num;完成。 (2)主要考查考生对 if语句的掌握,先看类的私有成员中关于 closed的定义:bool closed; true表示门关着。再看下一条语句: cout0) 当 j大于零时,做相乘操作,即完成该项的乘方动作 x_value*=x; j-; value+=coefi=*X value; 把 i项的乘方结果乘以该项系数后加进 value中 【试题解析】 题目要求成员函数 getVahe计算 多项式的值,多项式中 x的值由参数指定,多项式的值 value为各次项的累加和。由类的定义可知数组 coef中存储的是各次项的系数,这里使用 for循环来完成题目要求,当次项为 0时,value=coef0。当次项为 1时, value=coef1* x+coef0。依次类推直到 X的最高次数。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1