[计算机类试卷]国家二级C++机试(操作题)模拟试卷289及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷289及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷289及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 289及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1。其中有线段类 Line的定义。程序中位于每个 “ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是: End point 1 (1, 8), End point 2 (5, 2), length 7 2111。 注意:只修改每个 “ ERROR *found*水 ”下的那一行,不要改动程 序中的其他内容。 #include iostream #include cmath using namespac
2、e std; class Line; double length(Line); class Line 线段类 double x1, y1;线段端点 1 double x2, y2;线段端点 2 public: ERROR *found* Line(double x1, double y1, double x2, double y2)const this x1 x1; this y1 y1; this x2 x2; this y2 y2; double getXl()constreturnx1; double getYl()constreturny1; double getX2()constre
3、turnx2; ) double getY2()constreturny2; ) void show()const cout “End point 1 (“ x1 “, “ y1; cout “), End point 2 (“ x2 “, “ y2; ERROR *found* cout “), length “ length(this) “。 “ end1; ; double length(Line 1) ERROR *found* return sqrt(1 xl 1 x2)* (1 x1 1 x2) (1 y1 1 y2)*(1 y1 1 y2); int main() Line r1
4、(1 0, 8 0, 5 0, 2 0); r1 show(); return 0; 二、简单应用题 2 请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2。其中有向量基类 VectorBase、向量类 Vector和零向量类 ZeroVector的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序正确输出结果应为: (1, 2, 3, 4, 5) (0, 0, 0, 0, 0, 0) 注意:只能在横线处填写适当的代码,不要改动程序 中的其他内容,也不要删除或移动 “ *found*”。 #include iostream using namespa
5、ce std; class VectorBase向量基类,一个抽象类 int len; public: VectorBase (int fen): len(len) int length()constreturnlen; ) 向量长度。即向量中元素的个数 virtual double getElement(int i)const 0,取第 i个元素的值 virtual double sum()const 0;求所有元素的和 void show()const显示向量中所有元素 cout “(“; for(int i 0; i length() 1; i ) cout getElement(i)
6、“,“ *found* cout _ “)“ end1;显示最后一个元素 ; class Vector: public VectorBase向量类 double *va1; public: Vector(int len, double v NULL): VectorBase(len) val new doublelen; for(int i 0; i len; i ) vali (v NULL?0 0: v i ); *found* Vector()_; double getElement(int index) constreturn valindex; ) double sum()const
7、 double s 0 0; *found* for(int i 0, i length(); i )_; return s; ; class ZeroVector: public VectorBase零向量类 public: ZeroVector(int len): VectorBase(len) *found* double getElement(int index)const_; double sum()constreturn 0 0; ; int main() VectorBaSe *v; double d 1, 2, 3, 4, 5); V new Vector(5, d); V s
8、how(); delete v; v new ZeroVector(6); v show(); delete v; return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中声明了 SortedList类,是一个用于表示有序数据表的类。其成员函数 insert的功能是将一个数据插入到一个有序表中,使得该数据表仍然保持有序。请编写这个 insert函数。程序的正确输出应为: 插入前: 1, 2, 4, 5, 7, 8, 10 插入 6和 3后: 1, 2, 3, 4, 5, 6, 7, 8, 10 要求 : 补充编制的内容写在 “
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 289 答案 解析 DOC
