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

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

1、二级 C+机试-76 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:30.00)1.使用 VC6 打开考生文件夹下的工程 test40_1,此工程包含一个源程序文件 test40_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:The first result is 5The second result is 2The third result is 2The fourth result is 6源程序文件 test40_1.cpp 清单如下:#include iostream.hint subtraction (int a,

2、int b)int r;r=a-b;/* found */return int main ()int x=5, y=3, z;z = subtraction (7,2);cout “The first result is “ z /n;cout “The second result is “ subtraction(7,subtraction (7,2) /n;/* found */cout “The third result is “ subtraction (/* found */z= 4 + *subtraction (x,y);cout “The fourth result is “

3、z /n;return 0;(分数:30.00)填空项 1:_二、2简单应用题(总题数:1,分数:40.00)2.请编写一个函数 printdate(int year,int month,int day),该函数实现将输入的 3 个数字转换成英语数字纪年输出的功能,如输入 March9,1978,则输出 1978 3 9。注意:使用 switch 结构实现该函数的基本功能并应该能够判断错误的输入。部分源程序已存在文件 test40_2.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 printdate 的花括号中填写若干语句。源程序文件 rest40_2.cpp 清单如

4、下:#includeiostream.hvoid printdate(int year, int month, int day)void main()printdate(1978,3,9);(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.使用 VC6 打开考生文件夹下的工程 test40_3。此工程包含一个 test40_3.cpp,其中定义了类CVector,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)完成类 CVector 构造函数的定义,把传入的 int 型参数 a 和 b 分别赋值给类的成员变量 x 和 y。请在注释“/*1*”之后添加适

5、当的语句。(2)完成类 CVector 的“+”运算符重载函数的定义,使 Cvector 类的两个对象相加时可以直接使用符号“+”,并且结果仍然为类 Cvector 的对象,请在注释“/*2*”之后添加适当的语句。(3)在主函数中添加适当的语句,把类 Cvector 的对象 a 和 b 相加,并且把结果保存在对象 c 中,最后以“x,y”的形式输出在屏幕上,请在注释“/*3*”之后添加适当的语句。源程序文件 test40_3.cpp 清单如下:#include iostream.hclass CVectorpublic:int x,y;CVector () ;CVector (int,int)

6、CVector operator + (CVector);CVector:CVector (int a, int b)/*1*CVector CVector:operator+ (CVector param)/*2*temp.y = y + param.y;return (temp);int main ()CVector a (3,1);CVector b (1,2);CVector c;/*3*return 0;(分数:30.00)_二级 C+机试-76 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:30.00)1.使用 VC6 打开考生文件夹下的工程

7、 test40_1,此工程包含一个源程序文件 test40_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:The first result is 5The second result is 2The third result is 2The fourth result is 6源程序文件 test40_1.cpp 清单如下:#include iostream.hint subtraction (int a, int b)int r;r=a-b;/* found */return int main ()int x=5, y=3, z;z = subtraction (

8、7,2);cout “The first result is “ z /n;cout “The second result is “ subtraction(7,subtraction (7,2) /n;/* found */cout “The third result is “ subtraction (/* found */z= 4 + *subtraction (x,y);cout “The fourth result is “ z /n;return 0;(分数:30.00)填空项 1:_ (正确答案:(1) 错误;return (分数:40.00)_正确答案:(void printd

9、ate(int year, int month, int day)if(year0|month1|month12|day1|day31)cout“ERROR“;return;switch(month)case 1:cout“January“;break;case 2:cout“February“;break;case 3:cout“March“;break;case 4:eout“April“;break;case 5:cout“May“;break;case 6:cout“June“;break;case 7:cout“July“;break;case 8:cout“Auguest“;bre

10、ak;case 9:cout“September“;break;case 10:cout“October“;break;case 11:cout“November“;break;case 12:cout“December“;break;cout“ “day“,“yearendl;)解析:解析 本题考查的是考生对 switch 结构的应用。switch 分支结构也是常用的选择结构,对于每个 case 结构,只有遇到 break 才会中止并且跳出 switch 结构,否则会一直执行到下一个 break 或者switch 的结尾,而对于参数的预处理应该是程序健壮性的基本要求。三、3综合应用题(总题数

11、1,分数:30.00)3.使用 VC6 打开考生文件夹下的工程 test40_3。此工程包含一个 test40_3.cpp,其中定义了类CVector,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)完成类 CVector 构造函数的定义,把传入的 int 型参数 a 和 b 分别赋值给类的成员变量 x 和 y。请在注释“/*1*”之后添加适当的语句。(2)完成类 CVector 的“+”运算符重载函数的定义,使 Cvector 类的两个对象相加时可以直接使用符号“+”,并且结果仍然为类 Cvector 的对象,请在注释“/*2*”之后添加适当的语句。(3)在主函数中添加适

12、当的语句,把类 Cvector 的对象 a 和 b 相加,并且把结果保存在对象 c 中,最后以“x,y”的形式输出在屏幕上,请在注释“/*3*”之后添加适当的语句。源程序文件 test40_3.cpp 清单如下:#include iostream.hclass CVectorpublic:int x,y;CVector () ;CVector (int,int);CVector operator + (CVector);CVector:CVector (int a, int b)/*1*CVector CVector:operator+ (CVector param)/*2*temp.y =

13、y + param.y;return (temp);int main ()CVector a (3,1);CVector b (1,2);CVector c;/*3*return 0;(分数:30.00)_正确答案:(1)x=a;y=b;(2)CVector temp;temp.x=x+param.x;(3)c=a+b;toutc.x“,“c.y;)解析:解析 主要考查考生对于类的数据成员赋值与定义重载为成员函数的运算符函数的掌握,其中(2)就是运算符函数的实现,实际上就是通过已有的函数和符号实现复杂的运算功能,并最终返回该类的对象,注意最后的返回值必须是对象才能满足要求,(4)中使用对象调用类的数据成员用符号“.”。

展开阅读全文
相关资源
猜你喜欢
  • UL 104-2016 UL Standard for Safety Elevator Door Locking Devices and Contacts (Eleventh Edition Reprint with Revisions Through and Including May 20 2016)《升降机门锁装置和触点》.pdf UL 104-2016 UL Standard for Safety Elevator Door Locking Devices and Contacts (Eleventh Edition Reprint with Revisions Through and Including May 20 2016)《升降机门锁装置和触点》.pdf
  • UL 1040-1996 UL Standard for Safety Fire Test of Insulated Wall Construction (First Edition Reprint with Revisions Through and Including April 26 2017)《绝缘墙体结构的燃烧试验》.pdf UL 1040-1996 UL Standard for Safety Fire Test of Insulated Wall Construction (First Edition Reprint with Revisions Through and Including April 26 2017)《绝缘墙体结构的燃烧试验》.pdf
  • UL 1042 CRD-2014 UL Standard for Safety Electric Baseboard Heating Equipment - Section  Paragraph Reference 30 1 Subject Leakage Current Test (Edition 5 August 31 2009)《护壁板电加热设备的UL.pdf UL 1042 CRD-2014 UL Standard for Safety Electric Baseboard Heating Equipment - Section Paragraph Reference 30 1 Subject Leakage Current Test (Edition 5 August 31 2009)《护壁板电加热设备的UL.pdf
  • UL 1042-2009 UL Standard for Safety Electric Baseboard Heating Equipment (Fifth Edition Reprint with Revisions Through and Including December 14 2016)《护壁板电加热设备》.pdf UL 1042-2009 UL Standard for Safety Electric Baseboard Heating Equipment (Fifth Edition Reprint with Revisions Through and Including December 14 2016)《护壁板电加热设备》.pdf
  • UL 1046-2010 UL Standard for Safety Grease Filters for Exhaust Ducts (Fourth Edition Reprint with Revisions Through and Including April 17 2017)《排气管道用润滑脂过滤器》.pdf UL 1046-2010 UL Standard for Safety Grease Filters for Exhaust Ducts (Fourth Edition Reprint with Revisions Through and Including April 17 2017)《排气管道用润滑脂过滤器》.pdf
  • UL 1047-2015 UL Standard for Safety Isolated Power Systems Equipment (Sixth Edition).pdf UL 1047-2015 UL Standard for Safety Isolated Power Systems Equipment (Sixth Edition).pdf
  • UL 1053-2015 UL Standard for Safety Ground-Fault Sensing and Relaying Equipment (Seventh Edition Reprint with revisions through and including November 19 2015).pdf UL 1053-2015 UL Standard for Safety Ground-Fault Sensing and Relaying Equipment (Seventh Edition Reprint with revisions through and including November 19 2015).pdf
  • UL 1054-2013 UL Standard for Safety Special-Use Switches (Seventh Edition Reprint with revisions through and including October 24 2013)《专用开关》.pdf UL 1054-2013 UL Standard for Safety Special-Use Switches (Seventh Edition Reprint with revisions through and including October 24 2013)《专用开关》.pdf
  • UL 1058-2006 UL Standard for Safety Halogenated Agent Extinguishing System Units (Fourth Edition)《卤化剂灭火系统设备》.pdf UL 1058-2006 UL Standard for Safety Halogenated Agent Extinguishing System Units (Fourth Edition)《卤化剂灭火系统设备》.pdf
  • 相关搜索

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

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