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

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

1、国家二级 C+机试(操作题)模拟试卷 366 及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6 打开考生文件夹下的源程序文件 modilcpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: 10 6 30 2 2 注意:错误的语句在*error*的下面,修改该语句即可。#includeiostreamhclass CMyClasSprivate: int number; int Add(int i) return number+=i; int Sub(int i) return number 一=i; int Mul

2、int i) return number*=i; int Div(int i) if(i!=0) return number=i; else return number; *error* typedef int(FUNC)(int); *error* FUNC func;public: CMyClass() func0=CMyClass:Add; func1=CMyClass:Sub; func2=CMyClass:Mul; func3=CMyClass:Div; number=0; int CallFunction(int i,int j) *error* return(funci)(j)

3、 ;void mein() CMyClas S myobj; coutmyobjCallFunction(0,10)end1; coutmyobjCallFunction(1,4)end1; coutmyobjCallFunction(2,5)endl; coutmyobjCallFunction(3,15)endl; coutmyobjCallFunction(3,0)endl;(分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.使用 VC6 打开考生文件夹下的源程序文件 modi2cpp。请完成函数 fun(int x),该函数功能是判定 x的所有的约数,并且在函数中调用

4、写函数 WriteFile0 将结果输出到 modi2txt 文件中。 例如:x=10 的约数为 1,2,5,10。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 #inClude #include #inClude using namesPace std; void WriteFile(int c) ofstream out1; out1open(“modi2txt”,ios base:binary iosbase:app); out1*funci)(j);)解析:解析:CMyClass 类有一个成员变量 number,多个成员函数分别实现加减乘除功能。使用 ty

5、pedef定义了一个返回值是整型并带有一个整型参数的函数指针,并通过实例化一个容量为 4 的函数指针数组实现对类中定义的方法的调用。二、简单应用题(总题数:1,分数:2.00)2.使用 VC6 打开考生文件夹下的源程序文件 modi2cpp。请完成函数 fun(int x),该函数功能是判定 x的所有的约数,并且在函数中调用写函数 WriteFile0 将结果输出到 modi2txt 文件中。 例如:x=10 的约数为 1,2,5,10。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 #inClude #include #inClude using namesPac

6、e std; void WriteFile(int c) ofstream out1; out1open(“modi2txt”,ios base:binary iosbase:app); out1c_正确答案:(正确答案:for(int i=1;i=x;i+) if(xi=0) 如果 x 被 i 整除。那么 i 为 x 的约数 WriteFile(i); 将约数 i 存入文件 )解析:解析:(1)本题中函数的功能是求出约数。X 的约数就是能整除其的所有整数。可以从 1 开始到 X,计算取余。如果整除该数为 x 的约数。 (2)从已给部分源程序的 nmm 主函数开始入手,核心函数 void fu

7、n(int x)中的 x 参数为要计算约数的整数。三、综合应用题(总题数:1,分数:2.00)3.用 VC6 打开考生文件夹下的源程序文件 modi3cpp。其中定义的类并不完整,按照要求完成下列操作,将类的定义补充完整。在屏幕和程序 modi3txt 文件中输出以下结果: Hello Test 出现异常情况 其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整: (1)以追加的方式打开文件modi3txt,请在注释*1*后添加适当的语句。 (2)定义一个类对象 s,请在注释*2*后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数 main 与其他函数中的任何内容。 #

8、include #include using namespace std; void WriteFile(char*x) ofstream outl ; *1* outlopen(“modi3txt”,); outlx ; outlclose(); void ClearFile() ofstream outl; outlopen(“modi3txt”); outlclose(); Class TestClass public: TestClass() cout“Hello”“Test”“出现异常情况”_正确答案:(正确答案:(1)将“outlopen(“modi3txt“, );”补充完整为:outlopen(“modi3txt”,iosbase:app); (2)添加语句:TestClass s;)解析:

展开阅读全文
相关资源
猜你喜欢
  • BS EN ISO 26082-2-2012 Leather Physical and mechanical test methods for the determination of soiling Tumbling method《皮革 污迹测定的物理和机械试验 滚筒式清理方法》.pdf BS EN ISO 26082-2-2012 Leather Physical and mechanical test methods for the determination of soiling Tumbling method《皮革 污迹测定的物理和机械试验 滚筒式清理方法》.pdf
  • BS EN ISO 26203-2-2011 Metallic materials Tensile testing at high strain rates Servo-hydraulic and other test systems《金属材料 高应力率拉力试验 伺服液压和其它试验系统》.pdf BS EN ISO 26203-2-2011 Metallic materials Tensile testing at high strain rates Servo-hydraulic and other test systems《金属材料 高应力率拉力试验 伺服液压和其它试验系统》.pdf
  • BS EN ISO 26782-2009 Anaesthetic and respiratory equipment - Spirometers intended for the measurement of time forced expired volumes in humans《麻醉和呼吸设备 测量人类计时用力呼气量的肺活量计》.pdf BS EN ISO 26782-2009 Anaesthetic and respiratory equipment - Spirometers intended for the measurement of time forced expired volumes in humans《麻醉和呼吸设备 测量人类计时用力呼气量的肺活量计》.pdf
  • BS EN ISO 26800-2011 Ergonomics General approach principles and concepts《人类工效学 一般方法 原理和概念》.pdf BS EN ISO 26800-2011 Ergonomics General approach principles and concepts《人类工效学 一般方法 原理和概念》.pdf
  • BS EN ISO 26909-2010 Springs Vocabulary《弹簧 词汇表》.pdf BS EN ISO 26909-2010 Springs Vocabulary《弹簧 词汇表》.pdf
  • BS EN ISO 26945-2011 Metallic and other inorganic coatings Electrodeposited coatings of tin-cobalt alloy《金属和其它无机镀层 锡-钴合金的电镀层》.pdf BS EN ISO 26945-2011 Metallic and other inorganic coatings Electrodeposited coatings of tin-cobalt alloy《金属和其它无机镀层 锡-钴合金的电镀层》.pdf
  • BS EN ISO 26985-2012 Resilient floor coverings Identification of linoleum and determination of cement content and ash residue《弹性地板覆盖物 油地毡的鉴定和水泥含量及灰烬残余物的识别》.pdf BS EN ISO 26985-2012 Resilient floor coverings Identification of linoleum and determination of cement content and ash residue《弹性地板覆盖物 油地毡的鉴定和水泥含量及灰烬残余物的识别》.pdf
  • BS EN ISO 26986-2012 Resilient floor coverings Expanded (cushioned) poly(vinyl chloride) floor covering Specification《弹性地板覆盖物 扩展(加衬垫)聚乙烯(氯乙烯)地板覆盖物 规格》.pdf BS EN ISO 26986-2012 Resilient floor coverings Expanded (cushioned) poly(vinyl chloride) floor covering Specification《弹性地板覆盖物 扩展(加衬垫)聚乙烯(氯乙烯)地板覆盖物 规格》.pdf
  • BS EN ISO 26987-2012 Resilient floor coverings Determination of staining and resistance to chemicals《弹性地板覆盖物 着色和耐化学试剂的测定》.pdf BS EN ISO 26987-2012 Resilient floor coverings Determination of staining and resistance to chemicals《弹性地板覆盖物 着色和耐化学试剂的测定》.pdf
  • 相关搜索

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

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