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

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

1、二级 C+机试-18 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test17_1,此工程包含一个源程序文件 test17_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:Vehicle messageCar messageVehicle message源程序文件 test17_1.cpp 清单如下:#include iostream.hclass vehicleint wheels;float weight;public:/* found */void message(v

2、oid) cout“Vehicle message/n“;class car:public vehicleint passenger_load;public:/* found */void message (void)cout“Car message/n“;class truck:public vehicleint passenger_load;float payload;public:int passengers(void)return passenger_load;void main()vehicle * unicycle;unicycle=new vehicle;/* found */u

3、nicycle.message()delete unicycle;unicycle=new car;unicycle-message();delete unicycle;unicycle=new truck;unicycle-message();delete unicycle;(分数:33.00)填空项 1:_二、2简单应用题(总题数:1,分数:33.00)2.编写类 AA 的成员函数 int Compare(AAb), 该函数用于比较*this 与 b 的大小,若两者含有元素的个数n 相同,并且数组中前 n 个元素值对应相同,则认为两者相等返回 1,否则返回 0。注意:用数组方式及for 循

4、环来实现该函数。输出结果如下:a=baC注意:部分源程序已存在文件 testl7_2.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 Compare 的花括号中填写若干语句。文件 testl7_2.cpp 的内容如下:#includeiostream.h#includestdlib.hclass AA int *a;int n;int MS;public:void InitAA(int aa, int nn, int ms)if(nnms)cout“Error!“end1;exit(1);MS=ms;n=nn;a=new intMS;for(int i=0; in; i

5、) ai=aai;int Compare(AA b);int AA:Compare(AA b)void main()AA a,b,c;int x=1,2,3,4,5;int y=1,2,3,6,7;int z=1,2,5,7,9; a. InitAA(x,3,5); b. InitAA(y,3,5); c. InitAA(z,3,5);if (a.Compare(b)cout“a=b“end1;elsecout“ab“end1;if (a.Compare(c)cout“a=c“end1;elsecout“ac“end1;(分数:33.00)_正确答案:(int AA:Compare(AA b

6、)if(n!=bn) return 0;for(int i=0; in; i+)if(ai!=b.ai) return 0;return 1;)解析:解析本题考查的是考生应用 for 循环、if 条件控制语句等基本控制结构解决实际问题的能力。注意有多种返回 0 的情况:个数不等或者前 n 个数不等都要返回 0。三、3综合应用题(总题数:1,分数:34.00)3.使用 VC6 打开考生文件夹下的工程 test17_3,此工程包含一个源程序文件 test17_3.cpp,其中定义了用于表示点的类 Point 和表示内容的类 Text 以及二者的派生类 CircleWithText,但它们的定义并不

7、完整。请按要求完成下列操作,将它们的定义补充完整。(1)定义类 Point 的构造函数,请使用参数列表的形式将成员函数 x 和 y 分别初始化为参数 x1 和 y1 的值。请在注释“/*1*。”之后添加适当的语句。(2)完成类 Text 的构造函数 Text(char *str)的定义,将 char 型的 str 指向的内容赋值给 text 并且输出str 所指向的内容,请在注释“/*2*”之后添加适当的语句。(3)定义类 CircleWithText 的构造函数 CircleWithText(int cx,int cy,char *msg),int 型的 cx 和 cy用于赋值给 x 和 y

8、char 型的指针*msg 用于赋值给 text,请在注释“/*3*”之后添加适当的语句。输出结果如下:Point:3 4hello注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件 test17_3.cpp 清单如下:#include iostream.h#include string.hclass Pointint x,y;public:/*1*cout“Point:“x y/n;Point();class Textchar text100;public:Text(char *str)/*2*Text () ;class CircleWithText:public P

9、oint,public Textpublic:/*3*CircleWithText() ;void main()CircleWithText cm(3,4,“hello“);(分数:34.00)_正确答案:(1)Point(int x1=0,int y1=0):x(x1),y(y1)(2)strcpy(text,str);coutstr“/n“;(3)CircleWithText(int cx,int cy,char * msg):Point(cx,cy),Text(msg)解析:解析本题主要考查考生对于多继承中类的定义和派生类构造函数的定义的掌握。注意学会使用参数列表的形式定义派生类的构造函数,在列表中的格式是基类名 1(向基类传递的参数列表),基类名 2(向基类传递的参数列表)。

展开阅读全文
相关资源
猜你喜欢
  • BS PD ISO TR 24119-2015 Safety of machinery Evaluation of fault masking serial connection of interlocking devices associated with guards with potential free contacts《机械的安全性 带有零电势接触.pdf BS PD ISO TR 24119-2015 Safety of machinery Evaluation of fault masking serial connection of interlocking devices associated with guards with potential free contacts《机械的安全性 带有零电势接触.pdf
  • BS PD ISO TR 37121-2017 Sustainable development in communities Inventory of existing guidelines and approaches on sustainable development and resilience in cities《社区的可持续发展 城市可持续发展与.pdf BS PD ISO TR 37121-2017 Sustainable development in communities Inventory of existing guidelines and approaches on sustainable development and resilience in cities《社区的可持续发展 城市可持续发展与.pdf
  • BS PD ISO TR 4191-2014 Plastics piping systems for water supply Unplasticized poly(vinyl chloride)(PVC-U) and oriented PVC-U (PVC-O) Guidance for installation《供水用塑料管系统 未增塑聚氯乙烯(PVC-.pdf BS PD ISO TR 4191-2014 Plastics piping systems for water supply Unplasticized poly(vinyl chloride)(PVC-U) and oriented PVC-U (PVC-O) Guidance for installation《供水用塑料管系统 未增塑聚氯乙烯(PVC-.pdf
  • BS PD ISO TR 80001-2-6-2014 Application of risk management for IT-networks incorporating medical device Application guidance Guidance for responsibility agreements《包含医疗设备IT网络的风险管理应.pdf BS PD ISO TR 80001-2-6-2014 Application of risk management for IT-networks incorporating medical device Application guidance Guidance for responsibility agreements《包含医疗设备IT网络的风险管理应.pdf
  • BS PD ISO TR 80001-2-7-2015 Application of risk management for IT-networks incorporating medical devices Application guidance Guidance for Healthcare Delivery Organizations (HDOs)  .pdf BS PD ISO TR 80001-2-7-2015 Application of risk management for IT-networks incorporating medical devices Application guidance Guidance for Healthcare Delivery Organizations (HDOs) .pdf
  • BS PD ISO TS 11999-2-2015 PPE for firefighters Test methods and requirements for PPE used by firefighters who are at risk of exposure to high levels of heat and or flame while figh《.pdf BS PD ISO TS 11999-2-2015 PPE for firefighters Test methods and requirements for PPE used by firefighters who are at risk of exposure to high levels of heat and or flame while figh《.pdf
  • BS PD ISO TS 12720-2014 Sustainability in buildings and civil engineering works Guidelines on the application of the general principles in ISO 15392《建筑物和土木工程的可持续性 ISO 15392中的一般原则应用.pdf BS PD ISO TS 12720-2014 Sustainability in buildings and civil engineering works Guidelines on the application of the general principles in ISO 15392《建筑物和土木工程的可持续性 ISO 15392中的一般原则应用.pdf
  • BS PD ISO TS 13004-2013 Sterilization of health care products Radiation Substantiation of selected sterilization dose Method VDmaxSD《医疗保健产品的消毒 辐射 选定灭菌计量的证实 VDmaxSD法》.pdf BS PD ISO TS 13004-2013 Sterilization of health care products Radiation Substantiation of selected sterilization dose Method VDmaxSD《医疗保健产品的消毒 辐射 选定灭菌计量的证实 VDmaxSD法》.pdf
  • BS PD ISO TS 13399-3-2014 Cutting tool data representation and exchange Reference dictionary for tool items《切削工具数据表示和交换 工具项用参考字典》.pdf BS PD ISO TS 13399-3-2014 Cutting tool data representation and exchange Reference dictionary for tool items《切削工具数据表示和交换 工具项用参考字典》.pdf
  • 相关搜索

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

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