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

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

1、国家二级 C+机试(操作题)模拟试卷 468及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,此工程中含有一个源程序文件 proj1 cpp。其中位于每个注释 “ERROR*found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called The vallie is 10 Max number is 20 Destructor called 注 意:只能修改注释 “ ERROR*found*”的下一行语句,不要改动程序中的其他内容。 proj1 cpp #include using

2、namespace std; class MyClass public: ERROR *found* void NyClass(int i) value=i; couty?x: y; 求两个整数的最大值 ERROR*found* int Nax(int x, int y, int z=0) 求三个整数的最大值 if(xy) return xz?x: z; else return yz?y: z; int GetValueconstreturn value; NyClass()tout #include using namespace std; 平面坐标中的点 本题坐标系统中, x轴的正方向水平

3、向右, y轴的正方向竖直向下。 Class Point public: Point(double x=0 0, double y=0 0): x_(x), y_(y) double getX()constreturnx; double getY()constreturny_; 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), wi

4、dth(w), height(h) double area()const矩形面积 return width水 height; Point topLeft()const 左上角顶点 return point; Point bottomRight()const 右下角顶点 (注: y轴正方向竖直向下 ) *found* return Point(_); private: Point point;左上角顶点 double width;水平边长度 double height;垂直边长度 ; 圆形 class Cirole public: Circle(Point p, double r): cente

5、r(p), radius(r) Rectangle boundingBox ( ) const; 外切矩形 double area() consL圆形面积 *found* return PI*_; public: static const double PI;圆周率 private: Point center; 圆心 double radius; 半径 ; const double Circle: P3=3 14159; Rectangle Circle: boundingBox ()const *found* Point pt(_); int w, h; *found* w=h=_; ret

6、urn Rectangle(pt, w, h); int main() Point p(3, 2); Circle c(p, 1); cout using namespace std; class DataList数据表类 int len; double * d; public: DataList(int len, double data =NULL); DataList(DataList&data); int length()constreturn len; double getElement(int i) const(return di; DataList operator+(const

7、DataList&list)const;两个数据表求和 void show()const;显示数据表 ; void writeToFi le(char *, const DataList&); main cpp #include“DataList h“ DataList: DataList(int len, double data): fen(1en) d=new doublelen; for(int i=0; iy?x: y; 中两个形参变量都是 int型,而语句 int Max(int x, inty, int z=0)的前两个形参也都是 int型,第三个形参定义默认值,那么这两个 Max

8、函数在调用时它们的参数个数和参数类型都一样,因为函数重载要求形参类型或形参个数不同,所 以要把 int z=0改为 int z,才能构成函数重载。 (3)主要考查成员函数的调用,因为 value是私有成员,所以不能被类外函数直接调用,而且 value()的用法也是错误的,可以使用成员函数 obj GetValue()得到value的值。 二、简单应用题 2 【正确答案】 (1)point getX()+width, point getY()+height (2)radius*radius (3)center getX()一 radius, center getY()radius (4)2*ra

9、dius 【试题解析】 (1)主要考查考生对成员函数的掌握,程序要求返回右下角顶点,该点的 X坐标为左上角顶点的 X坐标加上 width,该点的 y坐标为左上角顶点 y坐标加上 height,即 return Point(point getX()+width,point getY()+height);。 (2)主要考查考生对成员函数的掌握,程序要求计算圆形面积,也就是返回圆面积,即 return PI*radius*radius;。 (3)主要考查考生对成员函数的掌握,首先看函数声明: Rectangle Circle:boundingBox()const,可知该函数要返回的是一个 Recta

10、ngle类型,即要返回的是圆的外切矩形。再看 Rectangle类的构造函数 Rectangle(Point p, int w, int h),由此可知,空格处要定义的点 pt为左上角点,即 Point pt(center getX()-radius,center getY()-radius);。 (4)由函数声明和 Rectangle类的构造函数可知, W和 h应该为直径,即W=h=2*adius;。 三、综合 应用题 3 【正确答案】 for(int i=0; i len; +i) 遍历对象 list中的数组和 d数组,把对应的值相加后放到数组 cid中。 ddi=di+list di; 【试题解析】 主要考查考生对重载运算符的掌握,题目要求对两个数据表求和。程序已经定义了动态数组 dd,并已经分配好了空间,接下来只要运用循环语句完成元素相加并进行赋值即可。

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

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

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