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

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

1、国家二级 C+机试(操作题)模拟试卷 292及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6打开考生文件夹下的源程序文件 modi1cpp,请修改程序中的错误,使程序能得出正确的结果: num:0 num:1 num:10 注意:不要改动 main函数,不能增行或删行,也不能更改程序的结构,错误的语句在*error*的下面。#includeiostreamhint i=10;Class TestClasspublic: TestClass(int i) cout“num:“iendl; *error* i=i+1; void Pri

2、nt()const cout“num:“iendl; private: int i;void main() *error* TestClass print; int i(0); printPrint(); *error* cout“num:“iendl; return ;(分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.使用 VC6打开考生文件夹下的源程序文件 modi2cpp。阅读下列函数说明和代码,完成空出部分程序,使函数 fun()实现以下功能:找出一个整数,它加上 100后是一个完全平方数,再加上 268又是一个完全平方数,请问该数是多少? 程序分析:在 10万以内判

3、断,先将该数加上 100后再开方,再将该数加上268后开方,如果开方后的结果满足条件,即是结果。 #include #include Void fun() int main() fun(); return 0; (分数:2.00)_三、综合应用题(总题数:1,分数:2.00)3.使用 VC6打开考生文件夹下的源程序文件 modi3cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能: (1)声明类 objA1,请在注释*1*后添加适当的语句。 (2)为类 objA0增加友元函数 func(),请在注释*2*后添加适当的语句。 (3)为类 objA1增加友元函数 f

4、unc(),请在注释*3*后添加适当的语句。 (4)函数func()返回 objA1对象中的变量和 objA0的静态变量的乘积,请在注释*4*后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。#includeiostreamh*1*class objA0private: static int m A0; *2*;int objA0m_A0=10;class objA1private: int m_A1; *3*public: objA1(int i) m_A1=i; ;int func(objA1obj) *4*int main() objA1

5、 obj 0(10); coutfunc(obj0)endl; return 0;(分数:2.00)_国家二级 C+机试(操作题)模拟试卷 292答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6打开考生文件夹下的源程序文件 modi1cpp,请修改程序中的错误,使程序能得出正确的结果: num:0 num:1 num:10 注意:不要改动 main函数,不能增行或删行,也不能更改程序的结构,错误的语句在*error*的下面。#includeiostreamhint i=10;Class TestClasspublic: TestCla

6、ss(int i) cout“num:“iendl; *error* i=i+1; void Print()const cout“num:“iendl; private: int i;void main() *error* TestClass print; int i(0); printPrint(); *error* cout“num:“iendl; return ;(分数:2.00)_正确答案:(正确答案:(1)this-i=i+1;或 TestClass:i=i+1:或(*this)i=i+1: (2)TestClass print(0); (3)cout“num:“:iendl;)解析

7、解析:(1)打开 modi1cpp,调试程序,显示错误提示为第二标识下“modi1cpp(22):error C2512:TestClass:no appropriate default constructor available”,主函数中首先调用的就是第2个标识下的 TestClass print函数,构造函数的名字和类的名字是一样的,而程序中给出的“TestClass print;”没有给出参数,所以程序调试时无法确定调用的函数。根据 TestClass构造函数“TestClass(int i)”的定义,应该存在 int型参数,并且题目要求第一次输出的值为“0”,所以第 2个标识正确的

8、调用函数为“TestClass print(0);”。 (2)运行,发现第一次的输出正确,但是第二次的输出值为“-858993460”,并不是题目中要求的“1”。在主函数中, 可知第二次输出调用的是“printPrint();”,即类 TestClass的成员函数“Print()”。成员函数 Print的定义“void Printoconst”中的输出语句为“cout”num:”ii=i+l;”或“TestClass:i=i+1;”或“(*this)i=i+1;”。 (3)主函数中通过“cout“num:“i“num:“:iendl;”。二、简单应用题(总题数:1,分数:2.00)2.使用 V

9、C6打开考生文件夹下的源程序文件 modi2cpp。阅读下列函数说明和代码,完成空出部分程序,使函数 fun()实现以下功能:找出一个整数,它加上 100后是一个完全平方数,再加上 268又是一个完全平方数,请问该数是多少? 程序分析:在 10万以内判断,先将该数加上 100后再开方,再将该数加上268后开方,如果开方后的结果满足条件,即是结果。 #include #include Void fun() int main() fun(); return 0; (分数:2.00)_正确答案:(正确答案:long int i,x,y,z; for(i=1;i100000;i+) x=Sqrt(i+

10、100); x为加上 100后开方后的结果 y=sqrt(i+268); y 为再加上 268后开方的结果 if(x*x=i+100y*y=i+268) 如果一个数的平方根的平方等于该数。 说明此数是完全平方数 coutiendl; )解析:解析:(1)利用循环找到满足条件的整数。 (2)首先计算 X加上 100和 Y加上 268的开方。 (3)一个数的平方根的平方等于该数,说明此数是完全平方数。三、综合应用题(总题数:1,分数:2.00)3.使用 VC6打开考生文件夹下的源程序文件 modi3cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能: (1)声明类

11、objA1,请在注释*1*后添加适当的语句。 (2)为类 objA0增加友元函数 func(),请在注释*2*后添加适当的语句。 (3)为类 objA1增加友元函数 func(),请在注释*3*后添加适当的语句。 (4)函数func()返回 objA1对象中的变量和 objA0的静态变量的乘积,请在注释*4*后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。#includeiostreamh*1*class objA0private: static int m A0; *2*;int objA0m_A0=10;class objA1privat

12、e: int m_A1; *3*public: objA1(int i) m_A1=i; ;int func(objA1obj) *4*int main() objA1 obj 0(10); coutfunc(obj0)endl; return 0;(分数:2.00)_正确答案:(正确答案:(1)添加语句:class objA1; (2)添加语句:friend int func(objA1obj); (3)添加语句:friend int func(objA1obj); (4)添加语句:return objm_A1*objA0:m_A0;)解析:解析:(1)类的声明格式为:“class类名;”,

13、因此第 1个标识下应添加“class objA1;”。(2)按照友元的定义格式,友元函数是在类声明中由关键字 friend修饰的非成员函数,func 函数在类外部给出了具体的实现形式,即“int func(objA1obj)”,因此第 2个标识下应添加“friend int func(objA1obj);”,这里参数是 0bjA1类对象 obj。 (3)第 3个标识下和题目 2要求一样,均是声明友元函数,因此第 2标识下应添加“friend intfunc(objA1obj);”。 (4)通过参数 obj对象可以直接访问 objm A1,objA0 的静态变量 m_A0是所有对象的共享成员,其访问形式为:objA0:m A0,因此第 4个标识下应添加“return objm_A1*objA0:m_A0;”。

展开阅读全文
相关资源
猜你喜欢
  • ETSI SR 002 176-2003 Electronic Signatures and Infrastructures (ESI) Algorithms and Parameters for Secure Electronic Signatures《电子签名和基础结构(ESI) 安全电子签名的算法和参数(版本1 1 1)》.pdf ETSI SR 002 176-2003 Electronic Signatures and Infrastructures (ESI) Algorithms and Parameters for Secure Electronic Signatures《电子签名和基础结构(ESI) 安全电子签名的算法和参数(版本1 1 1)》.pdf
  • ETSI SR 002 180-2003 Requirements for communication of citizens with authorities organizations in case of distress (emergency call handling) (V1 1 1)《危难发生时公民与政府当局 组织的通信要求(应急呼叫控制)(版.pdf ETSI SR 002 180-2003 Requirements for communication of citizens with authorities organizations in case of distress (emergency call handling) (V1 1 1)《危难发生时公民与政府当局 组织的通信要求(应急呼叫控制)(版.pdf
  • ETSI SR 002 180-2003 Requirements for communication of citizens with authorities organizations in case of distress (emergency call handling) (V1 1 1)《危难发生时公民与政府当局 组织的通信要求(应急呼叫控制)(版_1.pdf ETSI SR 002 180-2003 Requirements for communication of citizens with authorities organizations in case of distress (emergency call handling) (V1 1 1)《危难发生时公民与政府当局 组织的通信要求(应急呼叫控制)(版_1.pdf
  • ETSI SR 002 211-2006 Electronic communications networks and services Candidate list of standards and or specifications in accordance with Article 17 of Directive 2002 21 EC (V2 1 2.pdf ETSI SR 002 211-2006 Electronic communications networks and services Candidate list of standards and or specifications in accordance with Article 17 of Directive 2002 21 EC (V2 1 2.pdf
  • ETSI SR 002 211-2006 Electronic communications networks and services Candidate list of standards and or specifications in accordance with Article 17 of Directive 2002 21 EC (V2 1 2_1.pdf ETSI SR 002 211-2006 Electronic communications networks and services Candidate list of standards and or specifications in accordance with Article 17 of Directive 2002 21 EC (V2 1 2_1.pdf
  • ETSI SR 002 298-2003 Response from CEN and ETSI to the  Communication from the Commission to the Council the European Parliament the European Economic and Social Committee and the .pdf ETSI SR 002 298-2003 Response from CEN and ETSI to the Communication from the Commission to the Council the European Parliament the European Economic and Social Committee and the .pdf
  • ETSI SR 002 298-2003 Response from CEN and ETSI to the  Communication from the Commission to the Council the European Parliament the European Economic and Social Committee and the _1.pdf ETSI SR 002 298-2003 Response from CEN and ETSI to the Communication from the Commission to the Council the European Parliament the European Economic and Social Committee and the _1.pdf
  • ETSI SR 002 299-2004 Emergency Communications Collection of European Regulatory Principles (V1 1 1)《紧急通信 欧洲管理原则集(版本1 1 1)》.pdf ETSI SR 002 299-2004 Emergency Communications Collection of European Regulatory Principles (V1 1 1)《紧急通信 欧洲管理原则集(版本1 1 1)》.pdf
  • ETSI SR 002 451-2006 User Group SMEs as ICT users - Standardization perspective《用户组 SMEs作为ICT用户 标准化观点(版本1 1 1)》.pdf ETSI SR 002 451-2006 User Group SMEs as ICT users - Standardization perspective《用户组 SMEs作为ICT用户 标准化观点(版本1 1 1)》.pdf
  • 相关搜索

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

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