【计算机类职业资格】计算机二级(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 的返回值是指针类型的。

展开阅读全文
相关资源
猜你喜欢
  • ITU-T Y 2002-2009 Overview of ubiquitous networking and of its support in NGN (Study Group 13)《关于泛在网络及其在下一代网络(NGN)中的支撑综述 13号研究组》.pdf ITU-T Y 2002-2009 Overview of ubiquitous networking and of its support in NGN (Study Group 13)《关于泛在网络及其在下一代网络(NGN)中的支撑综述 13号研究组》.pdf
  • ITU-T Y 2006-2008 Description of capability set 1 of NGN release 1 (Study Group 13)《下一代网络(NGN)版本1中关于能力集1的描述 13号研究组》.pdf ITU-T Y 2006-2008 Description of capability set 1 of NGN release 1 (Study Group 13)《下一代网络(NGN)版本1中关于能力集1的描述 13号研究组》.pdf
  • ITU-T Y 2007-2010 NGN capability set 2 (Study Group 13)《(预发布)下一代网络(NGN)能力集2》.pdf ITU-T Y 2007-2010 NGN capability set 2 (Study Group 13)《(预发布)下一代网络(NGN)能力集2》.pdf
  • ITU-T Y 2011 FRENCH-2004 General principles and general reference model for Next Generation Networks《下一代网络的一般原则和通用参考模式 Y系列 全球信息基础设施网络协议方面和下一代网络 下一代网络框架和功能结构模型 13号研究组》.pdf ITU-T Y 2011 FRENCH-2004 General principles and general reference model for Next Generation Networks《下一代网络的一般原则和通用参考模式 Y系列 全球信息基础设施网络协议方面和下一代网络 下一代网络框架和功能结构模型 13号研究组》.pdf
  • ITU-T Y 2011 SPANISH-2004 General principles and general reference model for Next Generation Networks《下一代网络的一般原则和通用参考模式 Y系列 全球信息基础设施网络协议方面和下一代网络 下一代网络框架和功能结构模型 13号研究组》.pdf ITU-T Y 2011 SPANISH-2004 General principles and general reference model for Next Generation Networks《下一代网络的一般原则和通用参考模式 Y系列 全球信息基础设施网络协议方面和下一代网络 下一代网络框架和功能结构模型 13号研究组》.pdf
  • ITU-T Y 2011-2004 General principles and general reference model for next generation networks SERIES Y GLOBAL INFORMATION INFRASTRUCTURE INTERNET PROTOCOL ASPECTS AND NEXT GENERATIor.pdf ITU-T Y 2011-2004 General principles and general reference model for next generation networks SERIES Y GLOBAL INFORMATION INFRASTRUCTURE INTERNET PROTOCOL ASPECTS AND NEXT GENERATIor.pdf
  • ITU-T Y 2012-2010 Functional requirements and architecture of next generation networks (Study Group 13)《下一代网络的功能要求及架构 13号研究组》.pdf ITU-T Y 2012-2010 Functional requirements and architecture of next generation networks (Study Group 13)《下一代网络的功能要求及架构 13号研究组》.pdf
  • ITU-T Y 2013 FRENCH-2006 Converged services framework functional requirements and architecture《聚合业务框架的功能需求和体系结构 13号研究组》.pdf ITU-T Y 2013 FRENCH-2006 Converged services framework functional requirements and architecture《聚合业务框架的功能需求和体系结构 13号研究组》.pdf
  • ITU-T Y 2013 SPANISH-2006 Converged services framework functional requirements and architecture《聚合业务框架的功能需求和体系结构 13号研究组》.pdf ITU-T Y 2013 SPANISH-2006 Converged services framework functional requirements and architecture《聚合业务框架的功能需求和体系结构 13号研究组》.pdf
  • 相关搜索

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

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