【计算机类职业资格】二级C++分类模拟113及答案解析.doc
《【计算机类职业资格】二级C++分类模拟113及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++分类模拟113及答案解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+分类模拟 113 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“/ ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called. The value is 10 Max number is 20 Destructor called. 注意:只能修改注释“/ ERROR *found*”的下一行语句,不要改动程序中的其他内容。
2、 / proj1.cpp #include iostream using namespace std; class MyClass public: / ERROR *found* void MyClass (int i) value = i; cout “Constructor called.“ endl; int Max (int x, int y) return xy ? x : y; /求两个整数的最大值 / ERROR *found* int Max(int x, int y, int z = 0) /求三个整数的最大值 if (x y) return xz ? x : z; else
3、 return yz ? y : z; int GetValue () const return value; MyClass () cout “Destructor called.“ endl; private: int value; ; int main() MyClass obj(10); / ERROR *found* cout “The value is“ value() endl; cout “Max number is“ obj.Max(10,20) endl; return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答
4、题】菜单打开 proj2 下的工程 proj2,该工程中含有一个源程序文件proj2.cpp,请将堆栈类的定义补充完整。使程序的输出结果为: The element 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
5、 int Item * next; friend class Stack; ; 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 指向栈顶节
6、点 ret = top - item; top = top - next; delete temp; return ret; void Stack:Push (const int / *found* _; /使新节点的 next 指针指向栈顶数据 top = temp; int main() Stack s; for(int i=1; iSize; i +) s. Push(i); cout “The element of stack are:“; for(i=1; iSize; i +) cout s.Pop() “/t“; return 0; (分数:30.00)_三、综合应用题(总题数:
7、1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程文件 proj3,此工程中包含一个源程序文件proj3.cpp,其中定义了用于表示平面坐标系中的点的类 MyPoint 和表示矩形的类 MyRectangle;程序应当显示: (0,2)(2,2)(2,0)(0,0)4 但程序中有缺失部分,请按照以下提示,把缺失部分补充完整: (1)在“/ *1* *found*”的下方是构造函数的定义,它用参数提供的左上角和右下角的坐标对up_left 和 down_right 进行初始化。 (2)在“/ *2* *found*”的下方是成员函数 getDownLeft 的
8、定义中的一条语句。函数getDownLeft 返回用 MyPoint 对象表示的矩形的左下角。 (3)在“/ *3* *found*”的下方是成员函数 area 的定义,它返回矩形的面积。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。/ proj3.cpp #include iostream using namespace std; class MyPoint /表示平面坐标系中的点的类 double x; double y; public: MyPoint (double x, double y) this-x=x; this-y=y; do
9、uble getX() const return x; double getY() const return y; void show () const cout “(“ x “,“ y“)“ ; ; class MyRectangle /表示矩形的类 MyPoint up_left; /矩形的左上角顶点 MyPoint downright; /矩形的右下角顶点 public: MyRectangle (MyPoint upleft, MyPoint downright); MyPoint getUpLeft() const return up_left; /返回左上角坐标 MyPoint g
10、etDownRight() const return down_right; /返回右下角坐标 MyPoint getUpRight() const; /返回右上角坐标 MyPoint getDownLeft() const; /返回左下角坐标 double area() const; /返回矩形的面积 ; / *1* *found* MyRectangle:MyRectangle (_): up_left (p1), down_right (p2) MyPoint MyRectangle:getUpRight()const return MyPoint (down_right.getX(),
11、 up_left.getY(); MyPoint MyRectangle:getDownLeft()const / *2* *found* return MyPoint(_); / *3* *found* _ area() const return (getUpLeft().getX()-getDownRight().getX ()*(getDownRight().getY()-getUpLeft().getY(); int main() MyRectangle r (MyPoint (0, 2), MyPoint(2,0); r.getUpLeft().show(); r.getUpRigh
12、t().show(); r.getDownRight().show(); r.getDownLeft().show(); cout r.area() endl; return 0; (分数:40.00)_二级 C+分类模拟 113 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“/ ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor calle
13、d. The value is 10 Max number is 20 Destructor called. 注意:只能修改注释“/ ERROR *found*”的下一行语句,不要改动程序中的其他内容。 / proj1.cpp #include iostream using namespace std; class MyClass public: / ERROR *found* void MyClass (int i) value = i; cout “Constructor called.“ endl; int Max (int x, int y) return xy ? x : y; /求
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 分类 模拟 113 答案 解析 DOC
