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

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

1、二级 C+机试-85 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:30.00)1.使用 VC6 打开考生文件夹下的工程 test26_1,此工程包含一个源程序文件 test26_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:Values are: 1,2 and 3源程序文件 test26_1.cpp 清单如下;#include iostream.hclass CommonBasepublic:int x; /*found*/ class DeriveCommonA:public CommonBase public:int

2、y; ;class DeriveCommonB:public CommonBasepublic:int z;/*found*/ class Overlapping:public DeriveCommonA; public DeriveCommonBpublic:void Display()cout“Values are: “DeriveCommonA:x“, “y“ and “zend1;int main ( ) Overlapping ov; /*found*/ov.x=1;ov.y=2;ov.z=3;ov.Display();return 0; (分数:30.00)填空项 1:_二、2简单

3、应用题(总题数:1,分数:40.00)2.请编写函数 fun(),该函数的功能是判断字符串是否为回文,若是则函数返回 1,主函数中输出 YES:否则返回 0,主函数中输出 NO。回文是指顺读和倒读都一样的字符串。例如:字符串 LEVEL 是回文,而字符串 123312 就不是回文。注意;部分源程序已存在文件 test26_.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填写若干语句。文件 test26_2.cpp 的内容如下:#includeiostream.h#includestdio.h#define N 80int fun(char*str)v

4、oid main()char sN;cout“Enter a string:“endl;getss);cout“/n/n“;puts(s);if(fun(s)cout“YES/n“;elsecout“NO/n“;(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.使用 VC6 打开考生文件夹下的工程 test26_3。此工程包含一个 test26_3.cpp,其中定义了类 queue,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)完成类 queue 的无参数的构造函数的定义,要求把数据成员 bl 和 el 都初始化为 0,同时输出 queue init

5、ialized。请在注释“/*1*”之后添加适当的语句。(2)完成类 queue 的成员函数 qput(int j)的定义,它的功能是把新的元素加入队列,过程是先依据 bl 的值判断数组是否已经满了,如果是就输出 queue is full,否则 bl 自加一,并且把参数 j 的值存入 bl 指向的数组元素中,请在注释“/*2*”之后添加适当的语句。(3)完成类 queue 的成员函数 qget()的定义,它的功能是把队列开头的元素提取出队列,并返回该值,过程是先比较 el 和 bl 的值判断队列是否已空,如果是就输出 queue is empty,否则 el 自加一,并且把 el指向的数组元

6、素返回,请在注释“/ *3*”之后添加适当的语句。程序输出结果如下:queue initializedqueue initialized33 1144 22注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件 test26_3.cpp 清单如下:#includeiostream.hclass queueint q100;int bl,el;public:queue( );void qput(int j);int qget( );queue:queue( )/ *1*void queue:qput(int j)/ *2*cout“queue is full/n“;return;

7、bl+;qbl=j;int queue:qget( )/ *3*cout“queue is empty/n“;return 0;el+;return qel;void main( )queue aa,bb;aa.qput(11);bb.qput(22);aa.qput(33);bb.qput(44);coutaa.qget()“ “aa.qget()“/n“;coutbb.qget()“ “bb.qget()“/n“;(分数:30.00)_二级 C+机试-85 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:30.00)1.使用 VC6 打开考生文件夹下的工

8、程 test26_1,此工程包含一个源程序文件 test26_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:Values are: 1,2 and 3源程序文件 test26_1.cpp 清单如下;#include iostream.hclass CommonBasepublic:int x; /*found*/ class DeriveCommonA:public CommonBase public:int y; ;class DeriveCommonB:public CommonBasepublic:int z;/*found*/ class Overlappi

9、ng:public DeriveCommonA; public DeriveCommonBpublic:void Display()cout“Values are: “DeriveCommonA:x“, “y“ and “zend1;int main ( ) Overlapping ov; /*found*/ov.x=1;ov.y=2;ov.z=3;ov.Display();return 0; (分数:30.00)填空项 1:_ (正确答案:(1)错误:class DeriveCommonA:public CommonBase正确:class DeriveCommonA:public Comm

10、onBase(2)错误:class Overlapping:public DeriveCommonA;public DeriveCommonB正确:class Overlapping:public DeriveCommonA,public DeriveCommonB(3)错误:ov.x=1;正确:ov.DeriveCommonA:x=1;)解析:解析(1)主要考查考生对于派生类定义的理解,C+规定的继承格式是在类名的后面加冒号,之后是继承方式和继承类的名称,题目中错误的使用了作用域运算符;(2)主要考查考生是否掌握了多继承的定义,多继承的格式基本上和单继承相同,不过在多个基类之间应该使用逗号分

11、开,题目中错误的使用了分号,分号在 C+中是结束标志;(3)主要考查考生对于派生类的对象访问的掌握,x 是类 CommonBase 的成员,如果不加限制的访问就会产生二义性,编译程序不知道这个 x 是 A 类的,还是 B 类的,所以必须使用作用域限制符“:”,为了解决这个问题可以使用虚基类。二、2简单应用题(总题数:1,分数:40.00)2.请编写函数 fun(),该函数的功能是判断字符串是否为回文,若是则函数返回 1,主函数中输出 YES:否则返回 0,主函数中输出 NO。回文是指顺读和倒读都一样的字符串。例如:字符串 LEVEL 是回文,而字符串 123312 就不是回文。注意;部分源程序

12、已存在文件 test26_.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 fun 的花括号中填写若干语句。文件 test26_2.cpp 的内容如下:#includeiostream.h#includestdio.h#define N 80int fun(char*str)void main()char sN;cout“Enter a string:“endl;getss);cout“/n/n“;puts(s);if(fun(s)cout“YES/n“;elsecout“NO/n“;(分数:40.00)_正确答案:(int fun(char*str)int i,n=O

13、fg=1;char*p=str;while(*p)n+; p+;for(i=0;in/2;i+)if(stri=strn-1-i) ;elsefg=O;break;return fg;)解析:解析解答本题的主要思路是:首先要利用循环中指针的移动来求得字符串的长度 n,然后用一个for 循环依次取得数组中的前半部分元素,用取得的前半部分内的元素逐个与后半部分内的对应位置的元素进行比较,如果相同,不做任何工作,接着取下一个元素,继续比较:如果不相同,可以判断该字符串肯定不是回文,就给标志变量 fg 赋值 0(fg 的初始值为 1)。最终把 fg 作为函数的返回值返回(fg 值为 1表明是回文,f

14、g 值为 0 表明不是回文)。三、3综合应用题(总题数:1,分数:30.00)3.使用 VC6 打开考生文件夹下的工程 test26_3。此工程包含一个 test26_3.cpp,其中定义了类 queue,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)完成类 queue 的无参数的构造函数的定义,要求把数据成员 bl 和 el 都初始化为 0,同时输出 queue initialized。请在注释“/*1*”之后添加适当的语句。(2)完成类 queue 的成员函数 qput(int j)的定义,它的功能是把新的元素加入队列,过程是先依据 bl 的值判断数组是否已经满了,如果

15、是就输出 queue is full,否则 bl 自加一,并且把参数 j 的值存入 bl 指向的数组元素中,请在注释“/*2*”之后添加适当的语句。(3)完成类 queue 的成员函数 qget()的定义,它的功能是把队列开头的元素提取出队列,并返回该值,过程是先比较 el 和 bl 的值判断队列是否已空,如果是就输出 queue is empty,否则 el 自加一,并且把 el指向的数组元素返回,请在注释“/ *3*”之后添加适当的语句。程序输出结果如下:queue initializedqueue initialized33 1144 22注意:除在指定位置添加语句之外,请不要改动程序中

16、的其他内容。源程序文件 test26_3.cpp 清单如下:#includeiostream.hclass queueint q100;int bl,el;public:queue( );void qput(int j);int qget( );queue:queue( )/ *1*void queue:qput(int j)/ *2*cout“queue is full/n“;return;bl+;qbl=j;int queue:qget( )/ *3*cout“queue is empty/n“;return 0;el+;return qel;void main( )queue aa,bb

17、aa.qput(11);bb.qput(22);aa.qput(33);bb.qput(44);coutaa.qget()“ “aa.qget()“/n“;coutbb.qget()“ “bb.qget()“/n“;(分数:30.00)_正确答案:(1)bl=el=O;cout“queue initialized/n“;(2)if(bl=100)(3)if(el=bl)解析:解析主要考查考生对于具体的一个队列类的掌握,对列是一种特殊的存储结构,使用先进先出原则,题目中 bl 和 el 分别指向队列的开头和结尾,其中(2)是队列的标准插入操作, (3)是队列的标准的删除操作,注意它们的操作方式和先判断后操作的原则。

展开阅读全文
相关资源
猜你喜欢
  • EN 2337-2006 en Aerospace Series - Spherical Plain Bearings - Technical Specification《航空航天系列 球面关节轴承 技术规范》.pdf EN 2337-2006 en Aerospace Series - Spherical Plain Bearings - Technical Specification《航空航天系列 球面关节轴承 技术规范》.pdf
  • EN 2338-2001 en Aerospace Series - Sheets Hot Rolled in Titanium and Titanium Alloys - Thickness 0 8 mm Less Than or Equal to a Less Than or Equal to 6 mm - Dimensions《航空航天系列 热轧钛和钛.pdf EN 2338-2001 en Aerospace Series - Sheets Hot Rolled in Titanium and Titanium Alloys - Thickness 0 8 mm Less Than or Equal to a Less Than or Equal to 6 mm - Dimensions《航空航天系列 热轧钛和钛.pdf
  • EN 2339-2001 en Aerospace Series - Sheets Cold Rolled in Titanium and Titanium Alloys - Thickness 0 2 mm Less Than or Equal to a Less Than or Equal to 6 mm - Dimensions《航空航天系列 冷轧钛和.pdf EN 2339-2001 en Aerospace Series - Sheets Cold Rolled in Titanium and Titanium Alloys - Thickness 0 2 mm Less Than or Equal to a Less Than or Equal to 6 mm - Dimensions《航空航天系列 冷轧钛和.pdf
  • EN 234-1989 en Wallcoverings in Roll Form - Specification for Wallcoverings for Subsequent Decoration (Incorporates Amendment A1 1996)《卷式壁衬 后装饰壁衬规范》.pdf EN 234-1989 en Wallcoverings in Roll Form - Specification for Wallcoverings for Subsequent Decoration (Incorporates Amendment A1 1996)《卷式壁衬 后装饰壁衬规范》.pdf
  • EN 2344-2001 en Aerospace Series - Round Bars Machined in Heat Resisting Alloys - Diameter 10 mm Less Than or Equal to D Less Than or Equal to 180 mm - Dimensions《航空航天系列 耐热合金加工的圆形棒.pdf EN 2344-2001 en Aerospace Series - Round Bars Machined in Heat Resisting Alloys - Diameter 10 mm Less Than or Equal to D Less Than or Equal to 180 mm - Dimensions《航空航天系列 耐热合金加工的圆形棒.pdf
  • EN 2346-002-2006 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 002 General《航空航天系列 耐火电缆 工作温度在-65℃ ~260℃ 第002部分 总则》.pdf EN 2346-002-2006 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 002 General《航空航天系列 耐火电缆 工作温度在-65℃ ~260℃ 第002部分 总则》.pdf
  • EN 2346-003-2006 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 003 DL family single core - Product standard《航空航天系列 耐火电缆.pdf EN 2346-003-2006 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 003 DL family single core - Product standard《航空航天系列 耐火电缆.pdf
  • EN 2346-004-2006 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 004 DN family single UV laser printable and multicore as.pdf EN 2346-004-2006 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 004 DN family single UV laser printable and multicore as.pdf
  • EN 2346-005-2013 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 005 DW family single UV laser printable and multicore as.pdf EN 2346-005-2013 en Aerospace series - Cable electrical fire resistant - Operating temperatures between - 65 and 260 - Part 005 DW family single UV laser printable and multicore as.pdf
  • 相关搜索

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

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