【计算机类职业资格】二级C++分类模拟131及答案解析.doc
《【计算机类职业资格】二级C++分类模拟131及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++分类模拟131及答案解析.doc(11页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+分类模拟 131 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,其中有点类 Point 和线段类 Line 和主函数 main 的定义,程序中位于每个“/ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出应为: p1=(8,4)p2=(3,5) 注意:只修改两个“/ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream #include cmath using namespa
2、ce std; class Point double x, y; public: Point (double x = 0.0, double y = 0.0) / ERROR *found* x=x; y=y; double getX() const return x; double getY() const return y; / ERROR *found* void show() const cout “x“,“y“)“ ; class Line Point p1,p2; public: Line (Point pt1, Point pt2) / ERROR *found* pt1 = p
3、1; pt2 = p2; Point getP1() const return p1; Point getP2() const return p2; ; int main() Line line (Point(8, 4), Point(3,5); cout “p1 =“; line.getP1(). show(); cout “p2 =“; line.getP2(). show(); cout endl; return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,其中有整数栈类 IntL
4、ist、顺序栈类SeqList 和链接栈类 LinkList 的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 4 6 3 1 8 4 6 3 1 8 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动/“*found*”。 #include iostream using namespace std; class IntStack /整数栈类 public: virtual void push(int) = 0; /入栈 virtual int pop() = 0; /出栈并返回出栈元素 virtual int topE
5、lement() const = 0; /返回栈顶元素,但不出栈 virtual bool isEmpty() const=0; /判断是否栈空 ; class SeqStack: public IntStackint data100; /存放栈元素的数组 int top; /栈顶元素的小标 public: / *found* SeqStack():_ /把 top 初始化为-1 表示栈空 void push (int n) data+top = n; / *found* int pop() return_; int topElement() const return datatop; boo
6、l isEmpty() const return top = -1; ; struct Node int data; Node * next; ; class LinkStack: public IntStack Node * top; public: / *found* LinkStack():_ /把 top 初始化为 NULL 表示栈空 void push (int n) Node * p = new Node; p - data = n; / *found* _ top = p; int pop() int d=top-data; top=top-next; return d; int
7、 topElement() const return top - data; bool isEmpty() const return top = NULL; ; void pushData(IntStack st.push(1); st.push(3); st.push(6); st.push(4); void popData(IntStack int main() SeqStack st1; pushData(st1); popData(st1); cout endl; LinkStack st2; pushData(st2); popData(st2); cout endl; return
8、 0; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程 proj3,其中声明 IntSet 是一个用于表示正整数集合的类。IntSet 的成员函数 Intersection 的功能是求当前集合与另一个集合的交集。请完成成员函数Intersection。在 main 函数中给出了一组测试数据,此时程序的输出应该是: 求交集前: 1 2 3 5 8 10 2 8 9 11 30 56 67 求交集后: 1 2 3 5 8 10 2 8 9 11 30 56 67 2 8 要求: 补充编制的内容写在“/ *333*
9、”与“/ *666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 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 en
10、d = size - 1; for (int i = 0; i = end; i +) elementi = ai; bool IsMemberOf (int a) /判断 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 的元素 IntSet Intersection (IntSet /求当前集
11、合与集合 set 的交 void Print () /输出集合中的所有元素 for(int i=0;i=end;i+) if(i+1)% 20=0) cout elementi endl; else cout elementi “; cout endl; private: int elementMax; int end; ; void writeToFile (const char *); /main.cpp #include “IntSet.h“ IntSet IntSet:Intersection(IntSet / *333* / *666* return IntSet(a,size);
12、int main() int a = 1,2,3,5,8,10; int b = 2,8,9,11,30,56,67; IntSet set1 (a, 6), set2 (b, 7), set3; cout “求交集前:“ endl; set1.Print(); set2.Print(); set3.Print(); set3 = set1.Intersection (set2); cout endl “求交集后:“ endl; set1.Print(); set2.Print(); set3.Print(); writeToFile (“ “); return 0; (分数:40.00)_二
13、级 C+分类模拟 131 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,其中有点类 Point 和线段类 Line 和主函数 main 的定义,程序中位于每个“/ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出应为: p1=(8,4)p2=(3,5) 注意:只修改两个“/ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream #include cmath using namespace
14、 std; class Point double x, y; public: Point (double x = 0.0, double y = 0.0) / ERROR *found* x=x; y=y; double getX() const return x; double getY() const return y; / ERROR *found* void show() const cout “x“,“y“)“ ; class Line Point p1,p2; public: Line (Point pt1, Point pt2) / ERROR *found* pt1 = p1;
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 分类 模拟 131 答案 解析 DOC
