【计算机类职业资格】计算机二级(C++)上机考试5及答案解析.doc

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

1、计算机二级(C+)上机考试 5 及答案解析(总分:-3.00,做题时间:90 分钟)1.改错题 使用 VC6 打开考生文件夹下的工程 test17_1,此工程包含一个源程序文件 test17_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下: Vehicle message Car message Vehicle message 源程序文件 test17_1.cpp 清单如下: #include class vehicle int wheels; float weight; public: /* found */ void message(void) cout“Car

2、message/n“; ; class truck:public vehicle int passenger_load; float payload; public: int passengers(void)return passenger_load; ; void main() vehicle * unicycle; unicycle=new vehicle; /* found */ unicycle.message(); delete unicycle; unicycle=new car; unicycle-message(); delete unicycle; unicycle=new

3、truck; unicycle-message(); delete unicycle; (分数:-1.00)_2.简单应用题 请编写一个函数 int sum(int n),该函数完成 1+2+3+n 的运算,并返回运算结果,其中 n0。注意:请使用递归算法实现该函数。 注意:部分源程序已存在文件 test11_2.cpp 中。 请勿修改主函数 main 和其他函数中的任何内容,仅在函数 sum 的花括号中填写若干语句。 文件 test11_2.cpp的内容如下: #include int sum(int n) void main() int n; coutn; int result=sum(n

4、); coutgetpay(); cout“Car message/n“; ; class truck:public vehicle int passenger_load; float payload; public: int passengers(void)return passenger_load; ; void main() vehicle * unicycle; unicycle=new vehicle; /* found */ unicycle.message(); delete unicycle; unicycle=new car; unicycle-message(); dele

5、te unicycle; unicycle=new truck; unicycle-message(); delete unicycle; (分数:-1.00)_正确答案:((1)错误:void message(void) cout“Car message/n“; 正确:void message (void)coutmessage(); )解析:(1)主要考查考生对于虚函数使用规则的掌握,要实现对函数 message 的动态联编应该使用虚函数,否则产生的是静态联编,调用的函数输出结果就与要求不符; (2)主要考查考生对于流输出操作的掌握,该处错误的使用了流输入操作; (3)主要考查考生是否能分

6、清对象和对象指针,对象指针使用“-“调用成员函数,而对象使用“.“调用成员函数。 2.简单应用题 请编写一个函数 int sum(int n),该函数完成 1+2+3+n 的运算,并返回运算结果,其中 n0。注意:请使用递归算法实现该函数。 注意:部分源程序已存在文件 test11_2.cpp 中。 请勿修改主函数 main 和其他函数中的任何内容,仅在函数 sum 的花括号中填写若干语句。 文件 test11_2.cpp的内容如下: #include int sum(int n) void main() int n; coutn; int result=sum(n); coutgetpay(); coutputname(name); (emp+code)-putpay(pay); (4) char c50; double money; )解析:本题考查点为类成员的定义、类成员函数的定义与调用、对象数组的使用。注意指针和动态申请空间 new 的使用方法。使用指针调用成员应该用“-“符号,new 的返回值是指针类型的。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 12670-2002 Natural stone - Terminology German version EN 12670 2001《天然石料 技术》.pdf DIN EN 12670-2002 Natural stone - Terminology German version EN 12670 2001《天然石料 技术》.pdf
  • DIN EN 12671-2016 Chemicals used for treatment of water intended for human consumption - Chlorine dioxide generated in situ German version EN 12671 2016《人类用水处理用化学试剂 现场形成二氧化氯 德文版本EN.pdf DIN EN 12671-2016 Chemicals used for treatment of water intended for human consumption - Chlorine dioxide generated in situ German version EN 12671 2016《人类用水处理用化学试剂 现场形成二氧化氯 德文版本EN.pdf
  • DIN EN 12672-2016 Chemicals used for treatment of water intended for human consumption - Potassium permanganate German version EN 12672 2016《人类生活用水的处理用化学试剂 高锰酸钾 德文版本EN 12672-2016》.pdf DIN EN 12672-2016 Chemicals used for treatment of water intended for human consumption - Potassium permanganate German version EN 12672 2016《人类生活用水的处理用化学试剂 高锰酸钾 德文版本EN 12672-2016》.pdf
  • DIN EN 12673-1999 Water quality - Gas chromatographic determination of some selected chlorophenols in water German version EN 12673 1998《水质 水中选出的氯酚的气体色谱测定》.pdf DIN EN 12673-1999 Water quality - Gas chromatographic determination of some selected chlorophenols in water German version EN 12673 1998《水质 水中选出的氯酚的气体色谱测定》.pdf
  • DIN EN 12674-1-1999 Roll containers - Part 1 Terminology German version EN 12674-1 1999《滚筒式容器 第1部分 专业术语》.pdf DIN EN 12674-1-1999 Roll containers - Part 1 Terminology German version EN 12674-1 1999《滚筒式容器 第1部分 专业术语》.pdf
  • DIN EN 12674-2-2002 Roll containers - Part 2 General design and safety principles German version EN 12674-2 2001《滚动式容器 第2部分 一般设计和安全原则 德文版本 EN 12674-2 2001》.pdf DIN EN 12674-2-2002 Roll containers - Part 2 General design and safety principles German version EN 12674-2 2001《滚动式容器 第2部分 一般设计和安全原则 德文版本 EN 12674-2 2001》.pdf
  • DIN EN 12674-3-2005 Roll containers - Part 3 Test methods German version EN 12674-3 2004《滚动集装箱 第3部分 试验方法》.pdf DIN EN 12674-3-2005 Roll containers - Part 3 Test methods German version EN 12674-3 2004《滚动集装箱 第3部分 试验方法》.pdf
  • DIN EN 12674-4-2015 Roll containers - Part 4 Performance requirements German version EN 12674-4 2015《滚动集装箱 第4部分 性能要求 德文版本EN 12674-4-2015》.pdf DIN EN 12674-4-2015 Roll containers - Part 4 Performance requirements German version EN 12674-4 2015《滚动集装箱 第4部分 性能要求 德文版本EN 12674-4-2015》.pdf
  • DIN EN 12675-2017 Traffic signal controllers - Functional safety requirements German version EN 12675 2017《交通信号控制器 功能安全要求 德文版本EN 12675-2017》.pdf DIN EN 12675-2017 Traffic signal controllers - Functional safety requirements German version EN 12675 2017《交通信号控制器 功能安全要求 德文版本EN 12675-2017》.pdf
  • 相关搜索

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

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