ImageVerifierCode 换一换
格式:DOC , 页数:11 ,大小:49KB ,
资源ID:1324208      下载积分:5000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-1324208.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(【计算机类职业资格】二级C++分类模拟131及答案解析.doc)为本站会员(cleanass300)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

【计算机类职业资格】二级C++分类模拟131及答案解析.doc

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;

15、 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):x(x),y(y) 或this-x=x,this-y=y; (2)void show() const cout“(“x“,“

16、y“)“; (3):p1(pt1),p2(pt2) 或p1=pt1;p2=pt2 答案考生文件夹 考点 本题考查的是 Point 类和 Line 类,其中涉及构造函数、const 函数和成员函数。构造函数一般使用成员列表初始化,语句最后有个“;”作为结束符。 解析 (1)主要考查考生对构造函数的掌握,因为形参名和私有成员名称一样,因此不能直接赋值,在这里使用成员列表初始化,也可以使用 this 指针赋值。 (2)主要考查考生对语句基本语法的掌握,根据语句:void show() const cout“(“x“,“y“)“。可看出函数体内并没有“;”作为 cout 语句的结束符,因此程序错误。

17、3)主要考查考生对构造函数的掌握,形参是 pt1 和 pt2,这里写反了,也可以使用成员列表初始化法,可以避免这种错误。二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,其中有整数栈类 IntList、顺序栈类SeqList 和链接栈类 LinkList 的定义。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 4 6 3 1 8 4 6 3 1 8 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动/“*found*”。 #include iostre

18、am using namespace std; class IntStack /整数栈类 public: virtual void push(int) = 0; /入栈 virtual int pop() = 0; /出栈并返回出栈元素 virtual int topElement() const = 0; /返回栈顶元素,但不出栈 virtual bool isEmpty() const=0; /判断是否栈空 ; class SeqStack: public IntStackint data100; /存放栈元素的数组 int top; /栈顶元素的小标 public: / *found*

19、SeqStack():_ /把 top 初始化为-1 表示栈空 void push (int n) data+top = n; / *found* int pop() return_; int topElement() const return datatop; bool isEmpty() const return top = -1; ; struct Node int data; Node * next; ; class LinkStack: public IntStack Node * top; public: / *found* LinkStack():_ /把 top 初始化为 NU

20、LL 表示栈空 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 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(

21、IntStack int main() SeqStack st1; pushData(st1); popData(st1); cout endl; LinkStack st2; pushData(st2); popData(st2); cout endl; return 0; (分数:30.00)_正确答案:()解析:(1)top(-1) (2)datatop- (3)top(NULL) (4)p-next=top 答案考生文件夹 考点 本题考查的是 IntStack 类及其派生类 SeqStack 类和 LinkStack 类,其中涉及纯虚函数、数组、构造函数和动态数组。本题对栈的知识要求很

22、高,栈的特点是先进后出,后进先出。 解析 (1)主要考查考生对构造函数的掌握情况,先看语句注释:把 top 初始化为-1 表示栈空,即要把top 赋值为-1 即可。 (2)主要考查考生对纯虚函数的掌握情况,先看纯虚函数在基类的注释:出栈并返回出栈元素。要返回栈顶元素可以通过 datatop得到,出栈同时要使得 top 往下移动,即 top-。 (3)主要考查考生对构造函数的掌握情况,先看语句注释:把 top 初始化为 NULL 表示栈空,因此使用成员列表初始化直接把 top 赋值为 NULL 即可。 (4)主要考查考生对栈的掌握,push 为入栈函数,top 指向栈顶元素,因此新添加的指针的

23、next 要指向top,即 p-next=top;。三、综合应用题(总题数: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 要求: 补充编制的内

24、容写在“/ *333*”与“/ *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 -

25、 1; else end = 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 (I

26、ntSet /求当前集合与集合 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 IntSe

27、t(a,size); 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; (

28、分数:40.00)_正确答案:()解析:for (int i = 0; i = set.GetEnd(); i+) /遍对象 set 数组 if (IsMemberOf (set.GetElement (i) /判断对象 Set 数组第 i 个值是不是集合中的值,如果是则把它插入到 a 中 a size + = set.GetElement(i); 答案考生文件夹 考点 本题考查的是 IntSet 类,其中涉及构造函数、bool 函数和成员函数。本类是一个用于表示正整数集合的类,题目要求填写的函数能实现交集的功能,也就是将两个数组内的元素进行比较,将一样的元素提取出来。 解析 主要考查考生对数组的掌握,根据 IntSet 类的构造函数: 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; 可知数组 element 用来装载集合,end 表示数组长度,因此调用函数 IsMemberOf 来判断 set 中的元素是否存在于集合中,如果存在则放入数组 a 中。 主要考查考生对数组的掌握,集合可以用数组来实现,交集就是将两个数组中相等的元素提取出来放入一个新建立的数组。

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1