【计算机类职业资格】国家二级C++机试(操作题)模拟试卷389及答案解析.doc

上传人:tireattitude366 文档编号:1331887 上传时间:2019-10-17 格式:DOC 页数:3 大小:33KB
下载 相关 举报
【计算机类职业资格】国家二级C++机试(操作题)模拟试卷389及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】国家二级C++机试(操作题)模拟试卷389及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】国家二级C++机试(操作题)模拟试卷389及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C+机试(操作题)模拟试卷 389及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6打开考生文件夹下的源程序文件 modilcpp,该程序运行时有错,请改正其中的错误,使程序正常运行,即使程序在界面输出以下类似内容: 0012FF68 1 0012FF3C 5 0012FF6C 2 0012FF44 4 0012FF70 3 0012FF4C 3 0023FF74 4 0012FF54 2 0012FF78 5 0012FF5C 1 006AFDCC006AFDEF 数据可能因为机器的不同,程序的输出的内容会有差异。只要相差

2、为 4的连续地址即可。 注意:不要改动 main函数,不能增行或删行,也不能更改程序的结构, 错误的语句在*error*的下面。 #include using namespace std; int main() int*p,a5=1,2,3,4,5; double*q,b5=50,40,30,20,10); int x; p=a; q=b; *error* for(x=0;x=5;x+) *error* cout “ ” (p+x)“”q+x“”(q+x)_二、简单应用题(总题数:1,分数:2.00)2.使用 VC6打开考生文件夹下的源程序文件 modi2cpp。请完成函数 fun(char*

3、str,char ch),本函数采用二分法,在己按字母次序从小到大排序的字符数组 str中,查找字符 ch,若 ch在数组中,函数返回字符 ch在数组中的下标,否则返回一 1。 二分法查找的思想是:初始查找区间的下界为 0,上界为 len一1,查找区间的中后,k=(下界+上界)2;若 listk等于 ch,查找成功;若 listkch,则新的查找区间的下界不变,上界改为 k-1;否则新的查找区间的下界改为 k+1,上界不变。在新区间内继续用二分法查找。注意:请勿改动主函数 main与其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。#includeiostreamhint

4、fun(char*Str,char ch)Void msin() char Str=(a,b,c,d,e,f,g,h,i,j,k,0); char ch; cout“请输入一个字符:”end1; Cinch;cout“输入数字的位置是:”fun(Str,ch)end1; return;(分数:2.00)_三、综合应用题(总题数:1,分数:2.00)3.使用 VC6打开考生文件夹下的源程序文件 modi3cpp。此程序的运行结果为: In CDerives display()b=1 In CDerive2s display()b=2 其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。

5、 (1)定义函数 display()为无值型纯虚函数。请在注释*1*之后添加适当的语句。 (2)建立类 CDerive的构造函数,请在注释*2*之后添加适当的语句。 (3)完成类 CDerive2成员函数 diaplay0的定义。请在注释*3*之后添加适当的语句。 (4)定义类 Derivel的对象指针 d1,类 CDerive2的对象指针 d2。其初始化值分别为 1和 2。请在注释*4*之后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。 #include using namespace std; Class CBase public: CB

6、ase(int i)b=i;) *1* protected: int b; ; class CDerive:public CBase public: *2* void di splay() coutbdi splay(); void main() *4* func(d1); func(d2); (分数:2.00)_国家二级 C+机试(操作题)模拟试卷 389答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6打开考生文件夹下的源程序文件 modilcpp,该程序运行时有错,请改正其中的错误,使程序正常运行,即使程序在界面输出以下类似内容:

7、 0012FF68 1 0012FF3C 5 0012FF6C 2 0012FF44 4 0012FF70 3 0012FF4C 3 0023FF74 4 0012FF54 2 0012FF78 5 0012FF5C 1 006AFDCC006AFDEF 数据可能因为机器的不同,程序的输出的内容会有差异。只要相差为 4的连续地址即可。 注意:不要改动 main函数,不能增行或删行,也不能更改程序的结构, 错误的语句在*error*的下面。 #include using namespace std; int main() int*p,a5=1,2,3,4,5; double*q,b5=50,40

8、30,20,10); int x; p=a; q=b; *error* for(x=0;x=5;x+) *error* cout “ ” (p+x)“”q+x“”(q+x)_正确答案:(正确答案:(1)for(x=0 ; xp+x “” *(p+x) ”“ q+x ” ” *(q+x) endl;)解析:解析:本题的程序功能是输出相差为 4的连续地址。从己定源程序的 main主函数开始入手,依次执行程序中的语句,重点分析、调试标识下的错误语句,输出题目要求的结果。二、简单应用题(总题数:1,分数:2.00)2.使用 VC6打开考生文件夹下的源程序文件 modi2cpp。请完成函数 fun(c

9、har*str,char ch),本函数采用二分法,在己按字母次序从小到大排序的字符数组 str中,查找字符 ch,若 ch在数组中,函数返回字符 ch在数组中的下标,否则返回一 1。 二分法查找的思想是:初始查找区间的下界为 0,上界为 len一1,查找区间的中后,k=(下界+上界)2;若 listk等于 ch,查找成功;若 listkch,则新的查找区间的下界不变,上界改为 k-1;否则新的查找区间的下界改为 k+1,上界不变。在新区间内继续用二分法查找。注意:请勿改动主函数 main与其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。#includeiostreamh

10、int fun(char*Str,char ch)Void msin() char Str=(a,b,c,d,e,f,g,h,i,j,k,0); char ch; cout“请输入一个字符:”end1; Cinch;cout“输入数字的位置是:”fun(Str,ch)end1; return;(分数:2.00)_正确答案:(正确答案:int low=0; 初始查找区间的下界 int high; int k; for(high=0;strhigh!=0;high+) 求字符串长度 while(lowhigh)循环判断字符位置 k=(low+high)2; if(Strk=ch) return k

11、 else if(strkch) high=k-1; else low=k+1; if(Strlow=ch) return loW; return 一 1;)解析:解析:根据题干中给出的二分法查找思想,从己给部分源程序的 main主函数开始入手,核心函数int fun(char*str,char ch)中的 ch参数为输入的字符,其中返回值为 ch所在的位置。三、综合应用题(总题数:1,分数:2.00)3.使用 VC6打开考生文件夹下的源程序文件 modi3cpp。此程序的运行结果为: In CDerives display()b=1 In CDerive2s display()b=2 其中

12、定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义函数 display()为无值型纯虚函数。请在注释*1*之后添加适当的语句。 (2)建立类 CDerive的构造函数,请在注释*2*之后添加适当的语句。 (3)完成类 CDerive2成员函数 diaplay0的定义。请在注释*3*之后添加适当的语句。 (4)定义类 Derivel的对象指针 d1,类 CDerive2的对象指针 d2。其初始化值分别为 1和 2。请在注释*4*之后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。 #include using namespac

13、e std; Class CBase public: CBase(int i)b=i;) *1* protected: int b; ; class CDerive:public CBase public: *2* void di splay() coutbdi splay(); void main() *4* func(d1); func(d2); (分数:2.00)_正确答案:(正确答案:(1)添加语句:vi rtual Void di splay()=0 ; (2)添加语句:CDerive(i nt i):CBa se(i) (3)添加语句:void display()coutb解析:解析:程序中定义了类 CBase、CDerive 和 CDerive2,CDerive 和 CDerive2公有派生于类CBase,CDerive 和 CDerive2均有成员函数 display(),用于输出。函数 func(CBase*obj)的参数为 CBase对象指针,在函数体内通过该指针调用其 display()函数。

展开阅读全文
相关资源
猜你喜欢
  • EN 13880-7-2003 en Hot applied joint sealants Part 7 Function testing of joint sealants《热接合密封剂 第7部分 接合密封剂的功能试验》.pdf EN 13880-7-2003 en Hot applied joint sealants Part 7 Function testing of joint sealants《热接合密封剂 第7部分 接合密封剂的功能试验》.pdf
  • EN 13880-8-2003 en Hot applied joint sealants Part 8 Test method for the determination of the change in weight of fuel resistance joint sealants after fuel immersion《热接合密封剂 第8部分 浸入.pdf EN 13880-8-2003 en Hot applied joint sealants Part 8 Test method for the determination of the change in weight of fuel resistance joint sealants after fuel immersion《热接合密封剂 第8部分 浸入.pdf
  • EN 13880-9-2003 en Hot applied joint sealants - Part 9 Test method for the determination of compatibility with asphalt pavements《热接合密封剂 第9部分 与沥青路面兼容性测定的试验方法》.pdf EN 13880-9-2003 en Hot applied joint sealants - Part 9 Test method for the determination of compatibility with asphalt pavements《热接合密封剂 第9部分 与沥青路面兼容性测定的试验方法》.pdf
  • EN 13885-2005 en Food processing machinery - Clipping machines - Safety and hygiene requirements (Incorporates Amendment A1 2010)《食品加工机械剪切机 安全和卫生要求 包含修改件A1-2010》.pdf EN 13885-2005 en Food processing machinery - Clipping machines - Safety and hygiene requirements (Incorporates Amendment A1 2010)《食品加工机械剪切机 安全和卫生要求 包含修改件A1-2010》.pdf
  • EN 13886-2005 en Food processing machinery - Cooking kettles equipped with powered stirrer and or mixer - Safety and hygiene requirements (Incorporates Amendment A1 2010)《食品加工机械 装有.pdf EN 13886-2005 en Food processing machinery - Cooking kettles equipped with powered stirrer and or mixer - Safety and hygiene requirements (Incorporates Amendment A1 2010)《食品加工机械 装有.pdf
  • EN 13887-2003 en Structural adhesives Guidelines for surface preparation of metals and plastics prior to adhesive bonding《建筑粘合剂 粘结之前金属和塑料表面制备指南》.pdf EN 13887-2003 en Structural adhesives Guidelines for surface preparation of metals and plastics prior to adhesive bonding《建筑粘合剂 粘结之前金属和塑料表面制备指南》.pdf
  • EN 13888-2009 en Grout for tiles - Requirements evaluation of conformity classification and designation《瓷砖的灰浆 要求 合格评价 分类和命名》.pdf EN 13888-2009 en Grout for tiles - Requirements evaluation of conformity classification and designation《瓷砖的灰浆 要求 合格评价 分类和命名》.pdf
  • EN 13889-2003 en Forged steel shackles for general lifting purposes - Dee shackles and bow shackles - Grade 6 - Safety (Incorporates Amendment A1 2008)《一般提升用锻钢带销U形环 固定D形环钩和弓形环钩 6级 .pdf EN 13889-2003 en Forged steel shackles for general lifting purposes - Dee shackles and bow shackles - Grade 6 - Safety (Incorporates Amendment A1 2008)《一般提升用锻钢带销U形环 固定D形环钩和弓形环钩 6级 .pdf
  • EN 1389-2003 en Advanced technical ceramics - Ceramic composites - Physical properties - Determination of density and apparent porosity《高级工业陶瓷 陶瓷复合材料 物理性能 密度和表观孔隙率的测定》.pdf EN 1389-2003 en Advanced technical ceramics - Ceramic composites - Physical properties - Determination of density and apparent porosity《高级工业陶瓷 陶瓷复合材料 物理性能 密度和表观孔隙率的测定》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

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