[计算机类试卷]国家二级C++机试(操作题)模拟试卷59及答案与解析.doc

上传人:wealthynice100 文档编号:497617 上传时间:2018-11-28 格式:DOC 页数:6 大小:33KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷59及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷59及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷59及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷59及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷59及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级 C+机试(操作题)模拟试卷 59及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modil cpp,该程序运行时有错误,请改正其中的错误,使程序正确运行。并且使程序输出的结果为: OK 注意:错误的语句在 *error*的下面,修改该语句即可。 1 #include 2 class CBase 3 4 publiC: 5 CBase() 6 7 a=b=0 ; 8 9 private: 10 int a,b; 11 ; 12 class CDerivel: public CBase 13 14 public: 15 CDerivel() 16 17 18

2、error* 19 virtual void func(), 20 ; 21 class CDerive2: public CDerivel 22 23 public: 24 CDerive2() 25 26 a=0; 27 b=0; 28 29 void func() 30 31 *error* 32 coutfunc(); 44 二、简单应用题 2 使用 VC6打开考生文件夹下的源程序文件 modi2 cpp。完成函数 fun(int a, int n),实现递归函数 fun(int a, int n)的返回值是数组 a口的前 n个元素之和。 注意:不能修改程序的其他部分,只能修改 fu

3、n()函数。 1 #include 2 int fun(int a, int n) 3 4 5 6 void main() 7 8 int A=1, 2, 3, 4); 9 cout 2 #include 3 using namespace std; 4 void WriteFile(char*x) 5 6 ofstream outl, 7 *1* 8 outi open(“modi3 txt“, ); 9 outl ()=0,因此第 1个标识下 应为“virtual voidfunc()=0; ”。 func0函数没有参数表。 (2)编译程序后发现第 2个标识下有错误, cout流中的数据是

4、用流插入运算符“0) 2 return a In-1+fun(a, n-1); 递归求 n项的和 3 return 0; 项数小于等于 0,返回求和值 0 【试题解析】 (1)该程序功能是利用递归实现数组前 n项的和。函数的递归是在调用一个函数的过程中出现直接或间接调用该函数本身。 (2)从已 给部分源程序的 main主函数开始入手,核心函数 int fun(int a, int n)中调用该函数本身,利用递归调用实现计算结果,其中参数 a为数组名, n为要求和的项数。 解题思路 (1)如果要计算的项数小于等于 0,那么直接返回 0。 (2)否则调用递归语句 “an-1+fun(a, n-1)

5、实现 0到第 n项的和。 三、综合应用题 3 【正确答案】 (1)将 “outl open(“modi3 txt“, ); ”补充完整为:outl open(“modi3 txt“, los_base: app); (2)添加语句: TestClass s; 【试题解析】 本题中程序的功能是将字符串 “Hello”“Test”“出现异常情况 ”输入到文件 modi3 txt和屏幕上。在 VC环境下打开程序,根据题干给出的几条功能要求,对程序中给出注释下的内容逐个补全或修改。从已定源程序的 main主函数开始入手,可以看出程序通过调用类 TestClass和成员函数实现各种输出操作。 解题思路 (1)题目 1要求 “以追加的方式打开文件 modi3 txt”。文件输出输入方式的设置值 ,以 ios: app方式是以输出方式打开文件,写入的数据添加在文件末尾,即第 1个标识下语句补全为 “outl open(“modi3 txt“, ios_base: app); ”。 (2)题目 2要求 “定义一个类对象 S”。 C+中,在声明了类类型后,定义对象的一般形式:类名对象名。所以这里添加 “TestClass s; ”。

展开阅读全文
相关资源
猜你喜欢
  • ASTM B546-2004(2009) Standard Specification for Electric Fusion-Welded Ni-Cr-Co-Mo Alloy (UNS N06617) Ni-Fe-Cr-Si Alloys (UNS N08330 and UNS N08332) Ni-Cr-Fe-Al Alloy (UNS N06603) .pdf ASTM B546-2004(2009) Standard Specification for Electric Fusion-Welded Ni-Cr-Co-Mo Alloy (UNS N06617) Ni-Fe-Cr-Si Alloys (UNS N08330 and UNS N08332) Ni-Cr-Fe-Al Alloy (UNS N06603) .pdf
  • ASTM B546-2004(2014) Standard Specification for Electric Fusion-Welded Ni-Cr-Co-Mo Alloy (UNS N06617) Ni-Fe-Cr-Si Alloys (UNS N08330 and UNS N08332) Ni-Cr-Fe-Al Alloy (UNS N06603) .pdf ASTM B546-2004(2014) Standard Specification for Electric Fusion-Welded Ni-Cr-Co-Mo Alloy (UNS N06617) Ni-Fe-Cr-Si Alloys (UNS N08330 and UNS N08332) Ni-Cr-Fe-Al Alloy (UNS N06603) .pdf
  • ASTM B547 B547M-2002 Standard Specification for Aluminum and Aluminum-Alloy Formed and Arc-Welded Round Tube《成形的和电弧焊接的铝及铝合金圆管标准规范》.pdf ASTM B547 B547M-2002 Standard Specification for Aluminum and Aluminum-Alloy Formed and Arc-Welded Round Tube《成形的和电弧焊接的铝及铝合金圆管标准规范》.pdf
  • ASTM B547 B547M-2010 Standard Specification for Aluminum and Aluminum-Alloy Formed and Arc-Welded Round Tube《铝和铝合金成形和弧焊圆管的标准规范》.pdf ASTM B547 B547M-2010 Standard Specification for Aluminum and Aluminum-Alloy Formed and Arc-Welded Round Tube《铝和铝合金成形和弧焊圆管的标准规范》.pdf
  • ASTM B548-2003 Standard Test Method for Ultrasonic Inspection of Aluminum-Alloy Plate for Pressure Vessels《压力容器用铝合金板的超声波检验的标准试验方法》.pdf ASTM B548-2003 Standard Test Method for Ultrasonic Inspection of Aluminum-Alloy Plate for Pressure Vessels《压力容器用铝合金板的超声波检验的标准试验方法》.pdf
  • ASTM B548-2003(2009) Standard Test Method for Ultrasonic Inspection of Aluminum-Alloy Plate for Pressure Vessels《压力容器用铝合金板的超声波检验的标准试验方法》.pdf ASTM B548-2003(2009) Standard Test Method for Ultrasonic Inspection of Aluminum-Alloy Plate for Pressure Vessels《压力容器用铝合金板的超声波检验的标准试验方法》.pdf
  • ASTM B548-2003(2017) Standard Test Method for Ultrasonic Inspection of Aluminum-Alloy Plate for Pressure Vessels《压力容器用铝合金板超声波检验的标准试验方法》.pdf ASTM B548-2003(2017) Standard Test Method for Ultrasonic Inspection of Aluminum-Alloy Plate for Pressure Vessels《压力容器用铝合金板超声波检验的标准试验方法》.pdf
  • ASTM B549-2004 Standard Specification for Concentric-Lay-Stranded Aluminum Conductors Aluminum-Clad Steel Reinforced (ACSR AW)《包铝钢芯加强的同心绞捻铝导线(ACSR AW)标准规范》.pdf ASTM B549-2004 Standard Specification for Concentric-Lay-Stranded Aluminum Conductors Aluminum-Clad Steel Reinforced (ACSR AW)《包铝钢芯加强的同心绞捻铝导线(ACSR AW)标准规范》.pdf
  • ASTM B549-2010 Standard Specification for Concentric-Lay-Stranded Aluminum Conductors Aluminum-Clad Steel Reinforced for Use in Overhead Electrical Conductors《天花板电导线用包铝钢芯加强的同心绞捻铝导线.pdf ASTM B549-2010 Standard Specification for Concentric-Lay-Stranded Aluminum Conductors Aluminum-Clad Steel Reinforced for Use in Overhead Electrical Conductors《天花板电导线用包铝钢芯加强的同心绞捻铝导线.pdf
  • 相关搜索

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

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