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

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

1、二级 C+机试-31 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.return 0;(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.*(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.return 0;(分数:34.00)_二级 C+机试-31 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.return 0;(分数:33.00)_正确答案:(正确的类 Sample 的定义为:class Sampleprivate:int x;stat

2、ic int y;public:Sample(int a)x=a;y+=x;static void print(Sample s)cout“x“s.x“,y=“s.yend1;int Sample:y=5;)解析:解析 类 Sample 的定义中有两处错误。在类 Sample 中定义了静态成员函数 print()和静态数据成员 y。静态成员函数可以直接对类的静态数据成员进行访问,但是不能对类中非静态成员进行直接访问。所以错误在于语句“cout“x=“x“,y=“yend1;”,应该将其改为:“cout“x=“s.x“,y=“s.yend1;”。C+中,静态数据成员的初始化与一般数据成员不同。静

3、态数据成员初始化的格式如下:静态数据成员=值;所以语句“Sample:y=5,”缺少类型说明符 int。应该改为:int Sample:y=5;二、2简单应用题(总题数:1,分数:33.00)2.*(分数:33.00)_正确答案:(函数 fun()的定义如下:unsigned short fun(unsigned short s)int a5,i,sum=0;for(i=0;i5;i+)ai=(iht)(s/10000);s=s%1000000*10;sum+=ai;return (sum);)解析:解析 fun()函数的功能是将一个数的各位值相加并返回相加的值。所以本题的重点是如何将各位上的

4、数字求出来。本题可以采用穷举法计算,也可用类型转换法,即将这个数分别除以10000、1000、100、10(这是因为 unsigned short 类型的数不管在 16 位系统还是 32 位系统中,它总是占2 个字节,其最大值为 5 位数 65535),然后转化为 int 类型相加即可。三、3综合应用题(总题数:1,分数:34.00)3.return 0;(分数:34.00)_正确答案:(class Inherit:private Basesetx(a);y=b;z=c;m=d;void Inherit:display()constcoutgetx()“,“y“,“z“,“mend1;)解析:解析 类 Inherit 是类 Base 的公有派生类,即其派生方式为 public。类 Inherit 的成员函数setvalue()实现的功能是将基类成员 x、y、z 和派生类的数据成员 m 的值分别设置成 a、b、c 和 d。由于基类成员 x 为私有,所以可以在函数 setvalue()中通过调用基类公有成员 setx()函数给 x 赋值。其他数据成员可以直接赋值。在类体外定义类的常成员函数 display()时要注意带上修饰符 const,因为 const也是函数的组成部分。

展开阅读全文
相关资源
猜你喜欢
  • CSN ISO 7884-5-1994 Glass - Viscosity and viscometric fixed points - Part 5 Determination of working point by sinking bar viscometr《玻璃 粘度和粘度固定点 第5部分:下沉棒型粘度计工作点测定》.pdf CSN ISO 7884-5-1994 Glass - Viscosity and viscometric fixed points - Part 5 Determination of working point by sinking bar viscometr《玻璃 粘度和粘度固定点 第5部分:下沉棒型粘度计工作点测定》.pdf
  • CSN ISO 7884-6-1992 Glass Viscosity and viscometric fixed points - Part 6 Determination of softening point《玻璃 粘度和粘度固定点 第6部分:软化点测定》.pdf CSN ISO 7884-6-1992 Glass Viscosity and viscometric fixed points - Part 6 Determination of softening point《玻璃 粘度和粘度固定点 第6部分:软化点测定》.pdf
  • CSN ISO 7884-7-1994 Glass- Viscosity and viscometric fixed points - Part 7 Determination of annealing point and strain point by beam bending《玻璃 粘度和粘度固定点 第6部分:软化点测定》.pdf CSN ISO 7884-7-1994 Glass- Viscosity and viscometric fixed points - Part 7 Determination of annealing point and strain point by beam bending《玻璃 粘度和粘度固定点 第6部分:软化点测定》.pdf
  • CSN ISO 7884-8-1992 Glass Viscosity and viscometric fixed points - Part 8 Determination of (dilatometric) transformation temperature tg《玻璃 粘度和粘度固定 第8部分:膨胀变化温度的测定》.pdf CSN ISO 7884-8-1992 Glass Viscosity and viscometric fixed points - Part 8 Determination of (dilatometric) transformation temperature tg《玻璃 粘度和粘度固定 第8部分:膨胀变化温度的测定》.pdf
  • CSN ISO 789-6-1993 Agricultural tractors Test procedures Part 6 Centre of gravity《农业拖拉机 试验程序 第6部分:重心》.pdf CSN ISO 789-6-1993 Agricultural tractors Test procedures Part 6 Centre of gravity《农业拖拉机 试验程序 第6部分:重心》.pdf
  • CSN ISO 789-9-1993 Agricultural tractors Test procedures Part 9 Power tests for drawbar《农业拖拉机 试验程序 第9部分:牵引功率试验》.pdf CSN ISO 789-9-1993 Agricultural tractors Test procedures Part 9 Power tests for drawbar《农业拖拉机 试验程序 第9部分:牵引功率试验》.pdf
  • CSN ISO 793-1992 Aluminium and aluminium alloys - Determination of iron - - Orthophenanthroline photometric method《铝及铝合金 铁的测定 邻菲罗啉分光光度法》.pdf CSN ISO 793-1992 Aluminium and aluminium alloys - Determination of iron - - Orthophenanthroline photometric method《铝及铝合金 铁的测定 邻菲罗啉分光光度法》.pdf
  • CSN ISO 794-2-1993 Optical fibre cables Part 2 Product specification《光缆 第2部分 产品规格》.pdf CSN ISO 794-2-1993 Optical fibre cables Part 2 Product specification《光缆 第2部分 产品规格》.pdf
  • CSN ISO 7945-1994 Woodworking machines Single spindle boring machines Nomenclature and acceptance conditions《木工机床 单主轴钻挖机 术语与验收条件》.pdf CSN ISO 7945-1994 Woodworking machines Single spindle boring machines Nomenclature and acceptance conditions《木工机床 单主轴钻挖机 术语与验收条件》.pdf
  • 相关搜索

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

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