[计算机类试卷]国家二级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的最高次数。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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