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

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

1、二级 C+机试-36 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test15_1,此工程包含一个源程序文件 test15_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:My object has member 7源程序文件 test15_1.cpp 清单如下:#includeiostream.hclass MyClasspublic:MyClass(int mem)member=mem;MyClass()int GetAge()const return member;

2、private:int member;/*+*+* found */void main()int mem=7;/* found */MyClass myObj=MakeObject(mem);cout“My object has member“myObj-GetAge()endl;/* found */delete;MyClass *MakeObject(int mem)MyClass *pMyClass=new MyClass(mem);return pMyClass;(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.请编写一个函数 char MaxCharacmr(

3、char *str),该函数返回参数 str 所指向的字符串中具有最大ASCII 码的那个字符(如字符串“world”中字符w具有最大的 ASCII 码)。当 str 所指向的字符串为空时,则返回空字符 0x0 或/0。输出结果如下:Good Morning!Max char:r注意:部分源程序已存在文件 test15_2.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 MaxCharacter 的花括号中填写若干语句。文件 test15_2.cpp 的内容如下:#includeiostream.h#includestring.hchar MaxCharacter(ch

4、ar *str);void main()char str100;strcpy(str,“Good Morning!“);char maxc=MaxCharacter(str);coutstrendl;cout“Max char:“maxcendl;char MaxCharacter(char*str)(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.使用 VC6 打开考生文件夹下的工程 test15_3。此工程包含一个 test15_3.cpp,其中定义了类 Time 和Timex,Timex 公有继承 Time,但定义并不完整。请按要求完成下列操作,将程序补充完整。(

5、1)完成类 Time 构造函数的定义,将数据成员 hours 和 minutes 分别初始化为参数 new_hours 和new_minutes 的值。请在注释“/*1*”之后添加适当的语句。(2)完成类 Timex 的构造函数的定义,注意参数的传递。请在注释“/*2*”之后添加适当的语句。(3)请按时间格式“hour:minute”和“hour:minute:second”分别输出对象 time1 和 time2 所表示的时间,注意必须使用已经定义的成员函数。请在注释“/*3*”之后添加适当的语句。输出结果如下:20:3010:45:34注意:除在指定的位置添加语句外,请不要改动程序中的其他

6、语句。源程序文件 test15_3.cpp 清单如下:#includeiostream.hclass Timepublic:Time(int new_hours,int new_minutes)/ * 1 *int get_hours();int get_minutes();protected:int hours,minutes;int Time:get_hours()return hours;int Time:get_minutes()return minutes;class Timex:public Timepublic:Timex(int new_hours,int new_minute

7、s,int new_seconds);int get_seconds();protected:int seconds;/ * 2 *seconds=new_seconds;int Timex:get_seconds()return seconds;void main()Time time1(20,30);Timex time2(10,45,34);/ * 3 *(分数:34.00)_二级 C+机试-36 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test15_1,此工程包含一个源程序文件 test1

8、5_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:My object has member 7源程序文件 test15_1.cpp 清单如下:#includeiostream.hclass MyClasspublic:MyClass(int mem)member=mem;MyClass()int GetAge()const return member;private:int member;/*+*+* found */void main()int mem=7;/* found */MyClass myObj=MakeObject(mem);cout“My obje

9、ct has member“myObj-GetAge()endl;/* found */delete;MyClass *MakeObject(int mem)MyClass *pMyClass=new MyClass(mem);return pMyClass;(分数:33.00)_正确答案:(1)添加函数定义 MyClass *MakeObject(int mem);(2)错误:MyClass myObj=MakeObject(mem);正确:MyClass *myObj=MakeObject(mem);(3)错误:delete;正确:delete myObj;)解析:解析(1)主要考查考生对

10、于函数定义规则的理解,在使用前先定义,这是规定;(2)主要考查考生对于指针的掌握,因为函数返回值为指针,所以返回值必须赋值给一个指针类型的变量;(3)主要考查考生是否会使用 delete 释放空间,使用 delete 删除一个指针时,只需要直接把指针变量的名称写在后面。二、2简单应用题(总题数:1,分数:33.00)2.请编写一个函数 char MaxCharacmr(char *str),该函数返回参数 str 所指向的字符串中具有最大ASCII 码的那个字符(如字符串“world”中字符w具有最大的 ASCII 码)。当 str 所指向的字符串为空时,则返回空字符 0x0 或/0。输出结果

11、如下:Good Morning!Max char:r注意:部分源程序已存在文件 test15_2.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 MaxCharacter 的花括号中填写若干语句。文件 test15_2.cpp 的内容如下:#includeiostream.h#includestring.hchar MaxCharacter(char *str);void main()char str100;strcpy(str,“Good Morning!“);char maxc=MaxCharacter(str);coutstrendl;cout“Max char:

12、maxcendl;char MaxCharacter(char*str)(分数:33.00)_正确答案:(char MaxCharacter (char *str)if(str=NULL)return 0x0;char maxChar=0x0;int len=strlen(str);for(int i=0;ilen;i+)if(strimaxChar)maxChar=stri;return maxChar;)解析:解析本题考查的是考生应用 for 和 if 等基本控制语句解决实际问题的能力。注意字符的大小可以直接比较,实际上比较的就是字符的 ASCII 码的值。三、3综合应用题(总题数:1,

13、分数:34.00)3.使用 VC6 打开考生文件夹下的工程 test15_3。此工程包含一个 test15_3.cpp,其中定义了类 Time 和Timex,Timex 公有继承 Time,但定义并不完整。请按要求完成下列操作,将程序补充完整。(1)完成类 Time 构造函数的定义,将数据成员 hours 和 minutes 分别初始化为参数 new_hours 和new_minutes 的值。请在注释“/*1*”之后添加适当的语句。(2)完成类 Timex 的构造函数的定义,注意参数的传递。请在注释“/*2*”之后添加适当的语句。(3)请按时间格式“hour:minute”和“hour:mi

14、nute:second”分别输出对象 time1 和 time2 所表示的时间,注意必须使用已经定义的成员函数。请在注释“/*3*”之后添加适当的语句。输出结果如下:20:3010:45:34注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。源程序文件 test15_3.cpp 清单如下:#includeiostream.hclass Timepublic:Time(int new_hours,int new_minutes)/ * 1 *int get_hours();int get_minutes();protected:int hours,minutes;int Time:ge

15、t_hours()return hours;int Time:get_minutes()return minutes;class Timex:public Timepublic:Timex(int new_hours,int new_minutes,int new_seconds);int get_seconds();protected:int seconds;/ * 2 *seconds=new_seconds;int Timex:get_seconds()return seconds;void main()Time time1(20,30);Timex time2(10,45,34);/

16、 3 *(分数:34.00)_正确答案:(1)hours=new_hours;minutes=new_minutes;(2)Timex:Timex(int new_hours,int new_minutes,int new_seconds):Time(new_hours,new_minutes)(3)couttime1.get_hours()“:“time1.get_minutes()end1;couttime2.get_hours()“:“time2.get_minutes()“:“time2.get_seconds()endl;)解析:解析本题主要考查考生对于类和派生类构造函数的定义以及成员函数的使用,注意(2)中派生类构造函数中必须包括向基类传递参数的调用,应该使用参数列表完成这一操作。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN ISO 13473-5-2010 Characterization of pavement texture by use of surface profiles - Part 5 Determination of megatexture (ISO 13473-5 2009) German version EN ISO 13473-5 2009《.pdf DIN EN ISO 13473-5-2010 Characterization of pavement texture by use of surface profiles - Part 5 Determination of megatexture (ISO 13473-5 2009) German version EN ISO 13473-5 2009《.pdf
  • DIN EN ISO 13477-2008 Thermoplastics pipes for the conveyance of fluids - Determination of resistance to rapid crack propagation (RCP) - Small-scale steady-state test (S4 test) (IS.pdf DIN EN ISO 13477-2008 Thermoplastics pipes for the conveyance of fluids - Determination of resistance to rapid crack propagation (RCP) - Small-scale steady-state test (S4 test) (IS.pdf
  • DIN EN ISO 13478-2007 Thermoplastics pipes for the conveyance of fluids - Determination of resistance to rapid crack propagation (RCP) - Full-scale test (FST) (ISO 13478 2007) Engl.pdf DIN EN ISO 13478-2007 Thermoplastics pipes for the conveyance of fluids - Determination of resistance to rapid crack propagation (RCP) - Full-scale test (FST) (ISO 13478 2007) Engl.pdf
  • DIN EN ISO 13479-2010 Polyolefin pipes for the conveyance of fluids - Determination of resistance to crack propagation - Test method for slow crack growth on notched pipes (ISO 134.pdf DIN EN ISO 13479-2010 Polyolefin pipes for the conveyance of fluids - Determination of resistance to crack propagation - Test method for slow crack growth on notched pipes (ISO 134.pdf
  • DIN EN ISO 13482-2014 Robots and robotic devices - Safety requirements for personal care robots (ISO 13482 2014) German version EN ISO 13482 2014《机器人和机器人装置 个人护理机器人的安全要求 (ISO 13482-.pdf DIN EN ISO 13482-2014 Robots and robotic devices - Safety requirements for personal care robots (ISO 13482 2014) German version EN ISO 13482 2014《机器人和机器人装置 个人护理机器人的安全要求 (ISO 13482-.pdf
  • DIN EN ISO 13485 Berichtigung 1-2017 Medical devices - Quality management systems - Requirements for regulatory purposes (ISO 13485 2016) German version EN ISO 13485 2016 Corrigend.pdf DIN EN ISO 13485 Berichtigung 1-2017 Medical devices - Quality management systems - Requirements for regulatory purposes (ISO 13485 2016) German version EN ISO 13485 2016 Corrigend.pdf
  • DIN EN ISO 13485-2016 Medical devices - Quality management systems - Requirements for regulatory purposes (ISO 13485 2016) German version EN ISO 13485 2016《医疗器械 质量管理体系 调整要求(ISO 134.pdf DIN EN ISO 13485-2016 Medical devices - Quality management systems - Requirements for regulatory purposes (ISO 13485 2016) German version EN ISO 13485 2016《医疗器械 质量管理体系 调整要求(ISO 134.pdf
  • DIN EN ISO 13500-2011 Petroleum and natural gas industries - Drilling fluid materials - Specifications and tests (ISO 13500 2008 + AMD 1 2010) English version EN ISO 13500 2008 + A.pdf DIN EN ISO 13500-2011 Petroleum and natural gas industries - Drilling fluid materials - Specifications and tests (ISO 13500 2008 + AMD 1 2010) English version EN ISO 13500 2008 + A.pdf
  • DIN EN ISO 13501-2011 Petroleum and natural gas industries - Drilling fluids - Processing equipment evaluation (ISO 13501 2011) English version EN ISO 13501 2011《石油和天然气工业 钻井液 工艺设备的.pdf DIN EN ISO 13501-2011 Petroleum and natural gas industries - Drilling fluids - Processing equipment evaluation (ISO 13501 2011) English version EN ISO 13501 2011《石油和天然气工业 钻井液 工艺设备的.pdf
  • 相关搜索

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

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