【计算机类职业资格】二级C++笔试-332及答案解析.doc

上传人:sumcourage256 文档编号:1324570 上传时间:2019-10-17 格式:DOC 页数:23 大小:87KB
下载 相关 举报
【计算机类职业资格】二级C++笔试-332及答案解析.doc_第1页
第1页 / 共23页
【计算机类职业资格】二级C++笔试-332及答案解析.doc_第2页
第2页 / 共23页
【计算机类职业资格】二级C++笔试-332及答案解析.doc_第3页
第3页 / 共23页
【计算机类职业资格】二级C++笔试-332及答案解析.doc_第4页
第4页 / 共23页
【计算机类职业资格】二级C++笔试-332及答案解析.doc_第5页
第5页 / 共23页
点击查看更多>>
资源描述

1、二级 C+笔试-332 及答案解析(总分:100.00,做题时间:90 分钟)一、选择题(总题数:35,分数:70.00)1.下列表示纯虚函数的成员函数是(分数:2.00)A.virtual int func(int);B.void func(int)=0;C.virtual void func0;D.virtual void func(int)2.以下程序的输出结果为main()int m7,n=4;float a38.4,b=6.4,x;x=m/2+n*a/b+1/2;coutxend1;(分数:2.00)A.27.000000B.27.500000C.28.000000D.28.5000

2、003.为引入对象的同义词,对象的别名称为(分数:2.00)A.指针B.引C.枚举D.结构4.关于虚函数的描述中正确的是(分数:2.00)A.虚函数是一个静态成员函数B.虚函数是一个非成员函数C.虚函数既可以在函数说明时定义,也可以在函数实现时定又D.派生类的虚函数与基类中对应的虚函数具有相同的参数个数和类型5.所有在函数中定义的变量及函数的形式参数,都属于(分数:2.00)A.全局变量B.局部变量C.静态变量D.常量6.下列关于指针的操作中,错误的是(分数:2.00)A.两个同类型的指针可以进行比较运算B.可以用一个空指针赋给某个指针C.一个指针可以加上两个整数之差D.两个同类型的指针可以相

3、加7.执行下列语句后,输出结果为cout. put(s);cout,ca;(分数:2.00)A.caB.scaC.sD.a8.下面赋值语句中正确的是(分数:2.00)A.a=7+b+ca+7;B.a7+b+a+7;C.a=7+b,b+,a+7 ;D.a7+b,ca+7;9.对于下列语句,正确的判断是for(x0,y=O;(y! 123)void main()int a=10, b=20;couta“, “bend1;int a=0, b=0;for (int i=1;i8;i+)a+=i;b+=a;couta“, “b“, “: aend1;couta“, “bend1;(分数:2.00)填空

4、项 1:_43.对于下列语句char* strl = “Hello“;char * str2 =. “Hello“;*strl = P;coutstr2end1;其输出结果为: 【8】 (分数:2.00)填空项 1:_44.下列程序不能通过编译,应该在划线部分填写的语句是 【9】 。#includeiostream. h#includestdlib. hdouble Fune(int a, int b, char ch)double x;switch(ch)case +:x=double(a) +b;break;case -:x= double(a) -b;break;case /:x=dou

5、ble(a) * b;break;case /:if(B) x=double(a) /b;elseexit(1)breakdefault:exit(1);_void main()coutFunc(32 , 6 ,-) “,“;coutFunc(32, 6 ,*) “,“;coutFunc(32, 6 ,/) end1;(分数:2.00)填空项 1:_45.根据下面的主程序,完成类的一种构造函数的最简单形式。#includeiostream. hclass baseprivate:int num;public:【10】 ;void main()base try(6);(分数:2.00)填空项 1

6、46.下列程序的执行结果为 【11】 。#inciudeiostream, hint f(int i) return + +i; int g(int void main()int a, b;a=b=0;a+ =f(g(A) );b+=f(f(B) );cout%= “a“, b=“(bend1;(分数:2.00)填空项 1:_47.下列程序的运行结果是 【12】 。# includeiostream. hclass Apublic:virtual void use()cout “in A/n“; ;class B:public Apublic:virtual void use()cout

7、in B/n“;;class C: public Bpublic:virtual void use() cout “in C/n“; ; void main()A *obj;obi=new C;obj-use()delete obj;(分数:2.00)填空项 1:_48.完成下列类的构造函数,初始化语句为 【13】 。#include iostream. hclass Testprivate:int x, y;public,void Test(int initx, int inity)_void printx() coutx“y“=“x-y;;void main()Test x(300, 2

8、00);x. printx();(分数:2.00)填空项 1:_49.根据下列程序的执行结果,可以断定划线部分的修饰符应为 【14】 。执行结果:i9a football is created.a football is created.i=10a football is destroyed.a football is created.i=20a football is destroyed.a football is destroyed.源程序:# ineludeiostream. hclass Footballpublic:Football() cout“a football is crea

9、ted. “end1; Football() cout“a football is destroyed. “end1;void func(int i)_ Football f1;Football f2;cout“i= “iend1;void main()func(10);func(20);(分数:2.00)填空项 1:_50.下列程序的输出结果是 【15】 。# includeiostream. hclass MyClasspublic:int number;void set(int i);int number=3;void MyClass: :set (int i)number=i;void

10、 main( )MyClass my1;int number=10;my1. set(5),coutmy1, number,;my1. set(number);coutmy1. number,;my1. set(: :number);coutmy1. number.;(分数:2.00)填空项 1:_二级 C+笔试-332 答案解析(总分:100.00,做题时间:90 分钟)一、选择题(总题数:35,分数:70.00)1.下列表示纯虚函数的成员函数是(分数:2.00)A.virtual int func(int);B.void func(int)=0;C.virtual void func0;

11、D.virtual void func(int)解析:解析 本题考查纯虚函数的定义形式。由于纯虚函数在最后要有“=0“,故据此排除 A 和 D。而 B中没有出现 virtual 关键词,故正确答案为 C。2.以下程序的输出结果为main()int m7,n=4;float a38.4,b=6.4,x;x=m/2+n*a/b+1/2;coutxend1;(分数:2.00)A.27.000000 B.27.500000C.28.000000D.28.500000解析:解析 本题考查表达式值的类型由参与运算的所有变量的类型中优先级最高的变量类型所决定。不过要注意的是整型向 float 型转换时将丢失

12、小数部分,即向下驭值。3.为引入对象的同义词,对象的别名称为(分数:2.00)A.指针B.引 C.枚举D.结构解析:解析 引用是 C+引入的一个新概念,表示变量或对象的别名。4.关于虚函数的描述中正确的是(分数:2.00)A.虚函数是一个静态成员函数B.虚函数是一个非成员函数C.虚函数既可以在函数说明时定义,也可以在函数实现时定又D.派生类的虚函数与基类中对应的虚函数具有相同的参数个数和类型 解析:解析 虚函数不能定义为静态函数;虚函数的作用在于继承,表现出动态性。所以,在派生类中定义的虚函数必须和基类中对应的虚函数具有相同的参数个数和类型。5.所有在函数中定义的变量及函数的形式参数,都属于(

13、分数:2.00)A.全局变量B.局部变量 C.静态变量D.常量解析:解析 本题考查几种变量的作用域范围及其分类。6.下列关于指针的操作中,错误的是(分数:2.00)A.两个同类型的指针可以进行比较运算B.可以用一个空指针赋给某个指针C.一个指针可以加上两个整数之差D.两个同类型的指针可以相加 解析:解析 本题考查指针能够进行的运算方式。指针可以加减一个整数,两个指针可以相减,表示指针之间的元素个数。指针相加则没有意义,因此本题答案为 D。7.执行下列语句后,输出结果为cout. put(s);cout,ca;(分数:2.00)A.caB.sca C.sD.a解析:解析 本题很简单,考查 cou

14、t 对象的成员函数 put 方法和操作符的使用方法。8.下面赋值语句中正确的是(分数:2.00)A.a=7+b+ca+7;B.a7+b+a+7;C.a=7+b,b+,a+7 ;D.a7+b,ca+7; 解析:解析 赋值语句合法的重要标志之一就是赋值符号的左侧应该表示为一个变量,即可以在内存中存在一块空间用于存放赋值符号右侧的值。据此,可以断定选项 A 和 B 可以排除。注意;选项 C 中不是逗号表达式,要考虑优先级的问题。本题答案为 D。9.对于下列语句,正确的判断是for(x0,y=O;(y! 123)void main()int a=10, b=20;couta“, “bend1;int

15、a=0, b=0;for (int i=1;i8;i+)a+=i;b+=a;couta“, “b“, “: aend1;couta“, “bend1;(分数:2.00)填空项 1:_ (正确答案:a 重定义)解析:解析 在本题中 for 循环外围的大括号对没有实质含义,仅用于函数的作用城范围。如果去掉该括号,编译错误就会发生,因为变量 a 出现了重定义错误。43.对于下列语句char* strl = “Hello“;char * str2 =. “Hello“;*strl = P;coutstr2end1;其输出结果为: 【8】 (分数:2.00)填空项 1:_ (正确答案:Pello)解析:

16、解析 注意,两个字符串都没有名字,属字符串常量,在内容中是同一份内容。因此,对 strl进行重新赋值,仅仅替换了该字符数组的第一个字符。两个指针指向同一个字符串,因此输出为 Pello。44.下列程序不能通过编译,应该在划线部分填写的语句是 【9】 。#includeiostream. h#includestdlib. hdouble Fune(int a, int b, char ch)double x;switch(ch)case +:x=double(a) +b;break;case -:x= double(a) -b;break;case /:x=double(a) * b;break

17、case /:if(B) x=double(a) /b;elseexit(1)breakdefault:exit(1);_void main()coutFunc(32 , 6 ,-) “,“;coutFunc(32, 6 ,*) “,“;coutFunc(32, 6 ,/) end1;(分数:2.00)填空项 1:_ (正确答案:return x;)解析:解析 本题函数声明时指定了函数的返回值为 double,因此在函数体中必须存在一个 return 语句。45.根据下面的主程序,完成类的一种构造函数的最简单形式。#includeiostream. hclass baseprivate:in

18、t num;public:【10】 ;void main()base try(6);(分数:2.00)填空项 1:_ (正确答案:base(int n))解析:解析 注意,根据 main 函数中对类 base 的使用情况可知,base 类必须提供整型单参构造函数,同时要求构造其最简单的形式,故函数体为空。46.下列程序的执行结果为 【11】 。#inciudeiostream, hint f(int i) return + +i; int g(int void main()int a, b;a=b=0;a+ =f(g(A) );b+=f(f(B) );cout%= “a“, b=“(bend1

19、分数:2.00)填空项 1:_ (正确答案:a=3,b2)解析:解析 本题考查函数间引用传递的知识点。g(a)执行之后,返回值为 1,a 也变为 1,这就是引用传递的特点。然后执行 f(1),返回值为 2,此时 a2+1,故 a 此时为 3。由于 f(b)不具有引用传递的特征,因此,执行后 b=0+2,结果为 2。47.下列程序的运行结果是 【12】 。# includeiostream. hclass Apublic:virtual void use()cout “in A/n“; ;class B:public Apublic:virtual void use()cout “in B/

20、n“;;class C: public Bpublic:virtual void use() cout “in C/n“; ; void main()A *obj;obi=new C;obj-use()delete obj;(分数:2.00)填空项 1:_ (正确答案:in C)解析:解析 本题考查虚函数和多态性。原本 obj 指向祖先类,随后被赋值,指向新的子孙类,则在使用 use 这个重载的虚函数时,根据当前指向可确定调用子孙的同名虚函数。48.完成下列类的构造函数,初始化语句为 【13】 。#include iostream. hclass Testprivate:int x, y;pu

21、blic,void Test(int initx, int inity)_void printx() coutx“y“=“x-y;;void main()Test x(300, 200);x. printx();(分数:2.00)填空项 1:_ (正确答案:x=initx; y=inity;)解析:解析 本题考查的是类的私有数据如何从接口成员函数那里数据的。本题虽然简单,却体现了类的数据封装思想,并指明了如何完成这种封装。49.根据下列程序的执行结果,可以断定划线部分的修饰符应为 【14】 。执行结果:i9a football is created.a football is created.

22、i=10a football is destroyed.a football is created.i=20a football is destroyed.a football is destroyed.源程序:# ineludeiostream. hclass Footballpublic:Football() cout“a football is created. “end1; Football() cout“a football is destroyed. “end1;void func(int i)_ Football f1;Football f2;cout“i= “iend1;voi

23、d main()func(10);func(20);(分数:2.00)填空项 1:_ (正确答案:static)解析:解析 观察一下输出中对象的构造函数和析构函数的执行次数可以看出,再次进入时某对行没有被构造,亦即该对象在 func 执行后没有被销毁,再次进入时则不需要重构,可以体现这种功能的标识符只有 static。50.下列程序的输出结果是 【15】 。# includeiostream. hclass MyClasspublic:int number;void set(int i);int number=3;void MyClass: :set (int i)number=i;void main( )MyClass my1;int number=10;my1. set(5),coutmy1, number,;my1. set(number);coutmy1. number,;my1. set(: :number);coutmy1. number.;(分数:2.00)填空项 1:_ (正确答案:5,10,3)解析:解析 本题考查全局变量,局部变量和类的数据成员之间的使用上的差别。使用全局变量时需要用域作用符来限定该变量,否则编译器无法正确区分。

展开阅读全文
相关资源
猜你喜欢
  • ONORM S 5265-2-2001 Non-destructive testing - Radiation protection rules for technical application of gammagraphy Essais non-destructifs - Dispositions concemant la protection cont《非负.pdf ONORM S 5265-2-2001 Non-destructive testing - Radiation protection rules for technical application of gammagraphy Essais non-destructifs - Dispositions concemant la protection cont《非负.pdf
  • ONORM S 5270-1998 Radionuclide calibrators - Guidelines for the constancy testing in the field《放射性核素校准器 实地稳定性测试准则》.pdf ONORM S 5270-1998 Radionuclide calibrators - Guidelines for the constancy testing in the field《放射性核素校准器 实地稳定性测试准则》.pdf
  • ONORM S 5271-1997 Planar scintigraphy and Single photon emission computed tomography - Constancy tests of functional Performance characteristics《平面显像和单光子发射计算断层照相法 功能性能特点的稳定性测试》.pdf ONORM S 5271-1997 Planar scintigraphy and Single photon emission computed tomography - Constancy tests of functional Performance characteristics《平面显像和单光子发射计算断层照相法 功能性能特点的稳定性测试》.pdf
  • ONORM S 5275-1-2001 Nuclear medical therapy - Criterias for the discharge - Simplified calculation method for the discharge activity《核医学治疗 排放标准 放射性排放的简化计算方法》.pdf ONORM S 5275-1-2001 Nuclear medical therapy - Criterias for the discharge - Simplified calculation method for the discharge activity《核医学治疗 排放标准 放射性排放的简化计算方法》.pdf
  • ONORM S 5280-1-1998 Radon - Measuring methods and their r nge of applications《氡 测量方法及其应用范围》.pdf ONORM S 5280-1-1998 Radon - Measuring methods and their r nge of applications《氡 测量方法及其应用范围》.pdf
  • ONORM S 5290-1995 Medical electron accelerators - Constancy tests of functional Performance characteristics《医用电子加速器 功能性能特点的稳定性测试》.pdf ONORM S 5290-1995 Medical electron accelerators - Constancy tests of functional Performance characteristics《医用电子加速器 功能性能特点的稳定性测试》.pdf
  • ONORM S 5291-1997 Medical teletherapy Systems with gamma-emitting sources - Constancy tests of functional Performance characteristics《γ发射源远距医疗系统 功能性能特点的稳定性测试》.pdf ONORM S 5291-1997 Medical teletherapy Systems with gamma-emitting sources - Constancy tests of functional Performance characteristics《γ发射源远距医疗系统 功能性能特点的稳定性测试》.pdf
  • ONORM S 5292-1996 Medical remote-controlled automatically-driven afterloading Systems - Constancy tests of functional Performance characteristics《医用自动遥控的后负荷系统 功能性能特点的稳定性测试》.pdf ONORM S 5292-1996 Medical remote-controlled automatically-driven afterloading Systems - Constancy tests of functional Performance characteristics《医用自动遥控的后负荷系统 功能性能特点的稳定性测试》.pdf
  • ONORM S 5401-1990 Measuring and working conditions for the determination of sound power of machines for building constructions motor compressors《建筑机械声功率测定的测量和工作条件 电机压缩机》.pdf ONORM S 5401-1990 Measuring and working conditions for the determination of sound power of machines for building constructions motor compressors《建筑机械声功率测定的测量和工作条件 电机压缩机》.pdf
  • 相关搜索

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

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