【计算机类职业资格】二级C++分类模拟112及答案解析.doc
《【计算机类职业资格】二级C++分类模拟112及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++分类模拟112及答案解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+分类模拟 112 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,该工程中含有一个源程序文件proj1.cpp。其中位于每个注释“/ ERROR *found*”之后的一行语句有错误。请改正这些错误,使程序的输出结果为:1 2 3 4 5 6 7 8 9 10 注意:只能修改注释“/ ERROR *found*”的下一行语句,不要改动程序中的其他内容。 / proj1.cpp #include iostream using namespace std; c
2、lass MyClass public: MyClass(int len) array = new intlen; arraySize = len; for (int i = 0; i arraySize; i +) arrayi = i+1; MyClass() / ERROR *found* delete arrayi; void Print() const for (int i = 0; i arraySize; i +) / ERROR *found* cin arrayi “; cout endl; private: int * array; int arraySize; ; int
3、 main() / ERROR *found* MyClass obj; obj.Print(); return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,此工程中声明的 Array 是一个表示数组的类。一个 Array 对象可以包含多个整型元素。Array 的成员说明如下: 成员函数 add 用于向数组的末尾添加一个元素; 成员函数 get 用于获取数组中指定位置的元素; 数据成员 a 表示实际用于存储数据的整型数组; 数据成员 size 表示数组的容量,数组中的元素个数最多不能超过
4、 size; 数据成员 num 表示当前数组中的元素个数。 SortedArray 是 Array 的派生类,表示有序数组。SortedArray 重新定义了 Array 中的 add 函数,以确保有序数组中的元素始终按照升序排列。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为: 10,9,8,7,6,5,4,3,2,1, 1,2,3,4,5,6,7,8,9,10, 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/ *found*”。 #include iostream using namespace std; clas
5、s Array public: Array(unsigned int s) size = s; num= 0; a = new ints; virtual Array() delete a; virtual void add(int e) if (num size) / *found* _ num +; int get(unsigned int i) const if (i size) return ai; return 0; protected: int * a; unsigned int size, num; ; class SortedArray : public Array publi
6、c: / *found* SortedArray(unsigned int s) :_ virtual void add(int e) if (num = size) return; int i =0, j; while (i num) if (e ai) for (j =num; j i; j-) / *found* _; / *found* _; break; i+; if (i = num) ai = e; num +; ; void fun(Array for (i = 10; i = 1; i-) a.add (i); for (i = 0; i 10; i+) cout a.get
7、(i) “, “; cout endl; int main() Array a(10); fun(a); SortedArray sa(10); fun(sa); return 0; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程文件 proj3,此工程包含一个源程序文件proj3.cpp,其中定义了用于表示二维向量的类 MyVector;程序应当显示(6,8)。但程序中有缺失部分,请按照以下提示,把缺失部分补充完整: (1)在“/ *1* *found*”的下方是构造函数的定义,它用参数提供的坐标对 x 和
8、 y 进行初始化。(2)在“/ *2* *found*”的下方是减法运算符函数定义中的一条语句。两个二维向量相减生成另一个二维向量:其 X 坐标等于两向量 X 坐标之差,其 Y 坐标等于两向量 Y 坐标之差。 (3)在“/ *3* *found*”的下方,语句的功能是使变量 v3 获得新值,它等于向量 v1 与向量v2 之和。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。/ proj3.cpp #include iostream using std:ostream; using std:cout; using std:endl; class M
9、yVector /表示二维向量的类 double x; /X 坐标值 double y; /Y 坐标值 public: MyVector (double i = 0.0, double j = 0.0); /构造函数 MyVector operator + (MyVector j); /重载运算符+ friend MyVector operator - (MyVector i, MyVector j); /重载运算符- friend ostream /重载运算符 ; / *1* *found* _ (double i, double j): x(i),y(j) MyVector MyVecto
10、r:operator + (MyVector j) return MyVector (x + j. x, y + j. y); MyVector operator - (MyVector i, MyVector j) / *2* *found* return MyVector (_); ostream /输出向量 v 的坐标 return os; int main() MyVector v1(2,3), v2(4,5), v3; / *3* *found* v3 =_; cout v3 endl; return 0; (分数:40.00)_二级 C+分类模拟 112 答案解析(总分:100.0
11、0,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,该工程中含有一个源程序文件proj1.cpp。其中位于每个注释“/ ERROR *found*”之后的一行语句有错误。请改正这些错误,使程序的输出结果为:1 2 3 4 5 6 7 8 9 10 注意:只能修改注释“/ ERROR *found*”的下一行语句,不要改动程序中的其他内容。 / proj1.cpp #include iostream using namespace std; class MyClass public: MyClass
12、(int len) array = new intlen; arraySize = len; for (int i = 0; i arraySize; i +) arrayi = i+1; MyClass() / ERROR *found* delete arrayi; void Print() const for (int i = 0; i arraySize; i +) / ERROR *found* cin arrayi “; cout endl; private: int * array; int arraySize; ; int main() / ERROR *found* MyCl
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 分类 模拟 112 答案 解析 DOC
