[计算机类试卷]国家二级C++机试(操作题)模拟试卷278及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷278及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷278及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 278及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,此工程中含有一个源程序文件 proj1 epp。其中位于每个注释 “ERROR*found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called The value is 10 Max number is 20 Destructor called 注意 :只能修改注释 “ ERROR*found*”的下一行语句,不要改动程序中的其他内容。 proj1 cpp #include iostrea
2、m US ing namespace std; class MyClass public: ERROR*found* void MyClasS(int i) value i; cout ”Constructor called ” end1; int Max(int X, int Y)return X y?X: y; )求两个整数的最大值 ERROR*found* int Max(int x, int Y, int z 0) 求三个整数的最大值 if(x y) return x z?X: z; else return Y z?Y: z; int GetValue()constreturn val
3、ue; MyClass()cout “Destructor called “ end1; private: int value; ; int main() MyClasS obj(10); ERROR*found* cout “The value is“ value() end1; cout “Max number is“ obj Max(10, 20) end1; return 0; 二、简单应用题 2 请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2,该工程中含有一个源程序文 件 proj2 epp,请将堆栈类的定义补充完整。使程序的输出结果为: The el
4、ement of stack are: 4 3 2 1 注意:请勿修改主函数 main和其他函数中的任何内容,只在横线处编写适当代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 proj2 cpp #include ioStream USing namespace std; const int Size 5; class Stack; Class Item public: *found* Item(const int val): _ 构造函数对 item进行初始化 private: int item; Item * next; friend clasS Stack; ;
5、 class Stack public: Stack(): top(NULL) Stack(); int Pop(); void Push(const int ); private: Item * top; ; Stack Stack() Item * P top, *q; while(P! NULL) q P next; *found* _;释放 P所指向的 节点 p q; int Stack Pop() Item * temp; int ret; *found* _;使 temp指向栈顶节点 ret top item; top: top next; delete temp; return
6、ret; void Stack Push(const int&val) Item* temp new Item(val); *found*_; 使新节点的 next指针指向栈顶数据 top temp; int main() Stack s; for(int i 1; i Size; i ) s Push(i); cout “The element of stack are: “; for(i 1; i Size; i ) cout s Pop() t; return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程文件 proj3,此工程中包含一个源
7、程序文件 proj3 epp,其中定义了用于表示平面坐标系中的点的类 MyPoint和表示矩形的类 MyRectangle;程序应当显示: (0, 2)(2, 2)(2, 0)(0, 0)4 但程序中有缺失部分,请按照以下提示, 把缺失部分补充完整: (1)在 “ *1* *found*”的下方是构造函数的定义,它用参数提供的左上角和右下角的坐标对 up_left和 down_right进行初始化。 (2)在 “ *2* *found*”的下方是成员函数 getDownLeft的定义中的一条语句。函数 getDownLeft返回用 MyPoint对象表示的矩形的左下角。 (3)在 “ *3*
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 278 答案 解析 DOC
