【计算机类职业资格】国家二级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;)解析:

展开阅读全文
相关资源
猜你喜欢
  • CNS 14359-1999 Information technology-Coded representation of picture and audio information-Progressive bi-level image compression《信息技术-影音信息码化表示-渐进式双位准影像压缩》.pdf CNS 14359-1999 Information technology-Coded representation of picture and audio information-Progressive bi-level image compression《信息技术-影音信息码化表示-渐进式双位准影像压缩》.pdf
  • CNS 14360-1999 Broadband integrated services digital network (B-ISDN)-Functional description of the B-ISDN user part (B-ISUP) of signalling system no 7《宽频整体服务数字网络-第七号信号系统宽频整体服务数字网络.pdf CNS 14360-1999 Broadband integrated services digital network (B-ISDN)-Functional description of the B-ISDN user part (B-ISUP) of signalling system no 7《宽频整体服务数字网络-第七号信号系统宽频整体服务数字网络.pdf
  • CNS 14361-1999 Broadband integrated services digital network (B-ISDN)-General functions of messages and signals of theB-ISDN user part (B-ISUP) of signalling system no 7《宽频整体服务数字网络.pdf CNS 14361-1999 Broadband integrated services digital network (B-ISDN)-General functions of messages and signals of theB-ISDN user part (B-ISUP) of signalling system no 7《宽频整体服务数字网络.pdf
  • CNS 14362-1999 Broadband integrated services digital network (B-ISDN)-Signalling systme no 7 B-ISDN user part (B-ISUP)-Formats andcodes《宽频整体服务数字网络-第七号信号系统宽频整体服务数字网络使用者部-格式及码》.pdf CNS 14362-1999 Broadband integrated services digital network (B-ISDN)-Signalling systme no 7 B-ISDN user part (B-ISUP)-Formats andcodes《宽频整体服务数字网络-第七号信号系统宽频整体服务数字网络使用者部-格式及码》.pdf
  • CNS 14363-1999 Information technology-Open systems interconnection-Security frameworks for open systems Integrity framework《信息技术-开放系统互连-开放系统之安全框架:完整性框架》.pdf CNS 14363-1999 Information technology-Open systems interconnection-Security frameworks for open systems Integrity framework《信息技术-开放系统互连-开放系统之安全框架:完整性框架》.pdf
  • CNS 14364-1999 Information technology-Open systems interconnection-Security frameworks for open systems Security audit and alarmsframework《信息技术-开放系统互连-开放系统之安全框架:安全稽核及警报框架》.pdf CNS 14364-1999 Information technology-Open systems interconnection-Security frameworks for open systems Security audit and alarmsframework《信息技术-开放系统互连-开放系统之安全框架:安全稽核及警报框架》.pdf
  • CNS 14365-1999 Informationtechnology-Telecommunications and information exchange between systems-Transprot layer securityprotocol《信息技术-系统间的电信和信息交换-传送层安全协议》.pdf CNS 14365-1999 Informationtechnology-Telecommunications and information exchange between systems-Transprot layer securityprotocol《信息技术-系统间的电信和信息交换-传送层安全协议》.pdf
  • CNS 14366-1999 Segmentation principles for chinese literature processing《中文分词处理原则》.pdf CNS 14366-1999 Segmentation principles for chinese literature processing《中文分词处理原则》.pdf
  • CNS 14367-1999 Photography-Film dimensions-Micrographics《照相技术-胶卷尺度-用于微缩技术之胶卷》.pdf CNS 14367-1999 Photography-Film dimensions-Micrographics《照相技术-胶卷尺度-用于微缩技术之胶卷》.pdf
  • 相关搜索

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

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