【计算机类职业资格】二级C++-71及答案解析.doc
《【计算机类职业资格】二级C++-71及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-71及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+-71及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 prog1。其中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: v1=23;v2=42 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class MyClass int v1; static int v2; public: MyClas
2、s(int v) : vl (v) int getValue() const return v1; static int getValue(int dummy) / ERROR * found* return v1; ; / ERROR * found* int MyClass.v2 = 42; int main() MyClass obj (23); / ERROR * found* int v1 = obj.v1; int v2 = MyClass:getValue(0); cout “v1 = “ v1 “; v2 = “ v2 endl; return 0; (分数:30.00)_二、
3、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 prog2,其中定义了 Stack类和 Entry类。Stack是一个基于链式存储结构的栈,Entry 表示存储在栈中的数据顶。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream using namespace std; class Ent
4、ry public: Entry* next; int data; /* found* Entry (Entry * n, int d): _, data(d) ; class Stack Entry* top; public: Stack() : top(0) Stack() while (top!= 0) Entry* tmp = top; /* found* top =_; delete tmp; void push (int data) /* found* top = new Entry(_, data); int pop ( ) if (top = 0) return0; /* fo
5、und* int result = _; top = top-next; return result; ; int main ( ) int a = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9; Stack s; int i = 0; for (i = 0; i 10; i+) cout ai “; s.push(ai); cout endl; for (i = 0; i 10; i+) cout s.pop() ; cout endl; return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用答题菜单命令或直接用 VC6打开考生文
6、件夹下的工程 proj3,其中声明的 IntSet是一个用于表示正整数集合的类。IntSet 的成员函数 IsSubSet的功能是判断集合 B是否是集合 A的子集。在IsSubSet中可以使用成员函数 IsMembeOf睐判断一个正整数是否在此集合中,请编写成员函数IsSubSet。在 main函数中给出了一组测试数据,此时程序的输出应该为: 集合 A:1 2 3 5 8 10 集合B:2 8 集合 B是集合 A的子集 注意:只能在函数 IsSubSet的“/*333*”和“/*666*”之间填入若干语句,不要改动程序中的其他内容。 程序最后将结果输出到文件 out.dat中。输出函数 wri
7、teToFile已经编译为 obj文件,并且在本程序中调用。 /Intset.h #include iostream using namespace std; const int Max=100; class IntSet public: IntSet () /构造一个空集合 end=-1; IntSet (int a, int size) /构造一个包含数组 a中 size个元素的集合 if (size=Max) end=Max-1; else end = size-1; for(int i=0; i=end; i+) elementi=ai; bool IsMemberOf (int a)
8、 /判断 a是否为集合的元素 for(int i=0; i=end; i+) if (elementi = a) return true; return false; int GetEnd() return end; int getElement (int i) return elementi; /返回下标 i处的元素 bool IsSubSet (IntSet /判断集合set是否为当前集合的子集 void Print () /输出集合中的所有元素 for(int i=0; i=end; i+) if(i+1)% 20=0) cout elementi endl; else cout ele
9、menti ; cout endl; private: int elementMax; int end; ; void writeToFile (const char * ); /main.cpp #include “IntSet. h“ bool IntSet:IsSubSet(IntSet int b =2, 8; IntSet set1 (a, 6), set2 (b, 2); cout “集合 A:“; set1.Print (); cout “集合 B:“; set2.Print (); if (set1.IsSubSet (set2) cout “集合 B是集合 A的子集“ end
10、l; else cout “集合 B不是集合 A的子集“ endl; writeToFile (“); return 0; (分数:40.00)_二级 C+-71答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 prog1。其中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: v1=23;v2=42 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C71 答案 解析 DOC
