【计算机类职业资格】二级C++分类模拟101及答案解析.doc
《【计算机类职业资格】二级C++分类模拟101及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++分类模拟101及答案解析.doc(7页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+分类模拟 101 及答案解析(总分:100.00,做题时间:90 分钟)一、程序改错题(总题数:1,分数:30.00)1.使用 VC6 打开 下的源程序文件 modi.cpp,该程序运行时有错误,请改正其中的错误,使得程序正确运行。 程序输出: s1:n=20 s2:n=10 执行 s3.add(s1,s2) s3:n=30 s4:n=30 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在/*error*的下面。 #includeiostream.h class TestClass int n; public: TestClass() TestCla
2、ss (int m) n=m; /*error* TestClass add(TestClass s1, s2) this-n=s1 .n+s2. n; /*error* return (this); void disp () cout “n=“ n endl; /*error* void main() TestClass s1(20),s2(10),s3,s4; cout “s1:“; s1.disp () ; cout “s2:“; s2.disp(); s4=s3.add(s1,s2); cout “ 执行 s3.add(s1,s2) /ns3: “; s3.disp (); cout
3、(分数:30.00)_二、程序填空题(总题数:1,分数:30.00)2.使用 VC6 打开 下的源程序文件 modi2.cpp。完成 fun()函数,其功能是:将两个从小到大有序数组 a和 b,复制合并出一个有序整数序列 c,其中形参 n 和 m 分别是数组 a 和 b 的元素个数。 注意:不能修改程序的其他部分,只能修改 fun()函数。 #include iostream.h void fun (int a,int n,intb,int m, int *c) void main () int A=3, 5, 7,9, 11, 18,21; int B=6,15,19,21,39; int
4、C25, i; for(i=0;*25;*+) Ci = 0; cout “A=“; for (i=0; i7; i+) cout Ai “, “; cout endl; cout “B:“; for (i=0; icout Bi “, “; cout endl; fun(A,7,B,5,C) ; cout “C=“; for (i=0; i12; i+) cout Ci “, “; cout (分数:30.00)_三、程序设计题(总题数:1,分数:40.00)3.使用 VC6 打开 下的源程序文件 modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 (1)对文
5、件以追加的方式打开文件。请在注释/*1*后添加适当的语句。 (2)定义 m、n 为类 TestClass 的公有 int 型数据成员,请在注释/*2*后添加适当的语句。(3)定义 p 为类 TestClass 的数据成员指针,并指向类 TestClass 数据成员 m,请在注释/*3*后添加适当的语句。 (4)定义 P 指向类 TestClass 数据成员 n,请在注释/*4*后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。 #includeiostream.h #includefstream #includeiomanip #include
6、cmath using namespace std; void WriteFile(int x) ofstream out1; /*1* out1.open(“modi3.txt“, ); out1 x “ “; out1.close(); void ClearFile() ofstream out1; out1.open(“modi3.txt“); out1.close(); class TestClass public: void disp () cout “m=“ m endl; WriteFile(m); cout “n=“ n (分数:40.00)_二级 C+分类模拟 101 答案解
7、析(总分:100.00,做题时间:90 分钟)一、程序改错题(总题数:1,分数:30.00)1.使用 VC6 打开 下的源程序文件 modi.cpp,该程序运行时有错误,请改正其中的错误,使得程序正确运行。 程序输出: s1:n=20 s2:n=10 执行 s3.add(s1,s2) s3:n=30 s4:n=30 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在/*error*的下面。 #includeiostream.h class TestClass int n; public: TestClass() TestClass (int m) n=m; /*
8、error* TestClass add(TestClass s1, s2) this-n=s1 .n+s2. n; /*error* return (this); void disp () cout “n=“ n endl; /*error* void main() TestClass s1(20),s2(10),s3,s4; cout “s1:“; s1.disp () ; cout “s2:“; s2.disp(); s4=s3.add(s1,s2); cout “ 执行 s3.add(s1,s2) /ns3: “; s3.disp (); cout (分数:30.00)_正确答案:()
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 分类 模拟 101 答案 解析 DOC
