[计算机类试卷]国家二级(C++)机试模拟试卷48及答案与解析.doc

上传人:王申宇 文档编号:502497 上传时间:2018-11-29 格式:DOC 页数:6 大小:32KB
下载 相关 举报
[计算机类试卷]国家二级(C++)机试模拟试卷48及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级(C++)机试模拟试卷48及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级(C++)机试模拟试卷48及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级(C++)机试模拟试卷48及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级(C++)机试模拟试卷48及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级( C+)机试模拟试卷 48及答案与解析 一、程序改错题( 30分) 1 使用 VC6打开考生文件夹下的工程 test34_1,此工程包含一个源程序文件test34_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为: David 3123 1000 源程序文件 test34_1.cpp清单如下: #include iostream.h #include string.h class person public: char name20; unsigned long id; float salary; void print()cout name id salary

2、 /* found */ void main( ) person p; person *ptr; /* found */ ptr=p; /* found */ strcpy(“David“,ptr- name); ptr- id=3123; ptr- salary=1000; ptr- print(); 二、简单应 用题( 40分) 2 请编写一个函数 display(),该函数要求用户先输入一字符串,然后在屏幕上再输出该字符串 (假设该字符串长度小于 100)。注意:部分源程序已存在文件test35_2.cpp中, 请勿修改主函数 main和其他函数中的任何内容,仅在函数 display()

3、的花括号中填写若干语句。 如输入 abc,输出结果如下: please input string: abe abc Press any key to continue 文件 test35_2.cpp 的内容如下 : #include iostream.h #include conio.h void display() void main( ) cout“please input string:“ end1; display ( ); 三、综合应用题( 30分) 3 使用 VC6打开考生文件夹下的工程 test33_3。此工 程包含一个 test33_3.cpp,其中定义了表示时间的类 Time

4、,但 Time类定义并不完整。请按要求完成下列操作,将程序补充完整。 (1)定义类 Time的私有数据成员 hours、 minutes和 seconds,它们都是 int型的数据,分别表示时间的小时、分和秒。请在注释 “/*1*”之后添加适当的语句。 (2)完成类 Time缺省构造函数的定义,该函数将数据成员 hours、 minutes和seconds的值初始化为 0,请在注释 “/* 2*”之后添加适当的语句。 (3)完成类 Time带参构造函数的定义,该函数将数据成员 hours、 minutes和seconds的值分别初始化为参数 h、 m和 s的值,请在注释 “/*3*”之后添加适

5、当的语句。 (4)完成类 Time中运算符 “+”的重载,注意小时、分和秒在相加时的进位问题。请在注释 “/*4*”之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 程序输出结果如下: 8: 17: 11 源程序文件 test33_3.cpp清单如下: #include iostream.h class Time /* 1 * public: Time ( ) /* 2 * seconds=0; Time(int h, int m, int s) /* 3 * minutes=m; seconds=s; Time operator +(Time void ge

6、ttime(); ; Time Time:operator +(Time m=time.minutes+minutes+s/60; h=time.hours+hours+m/60; Time result(h,m%60,s%60); return result; void Time:gettime() cout hours “:“ minutes “:“ seconds end1; void main( ) Time t1(3,20,15),t2(4,56,56),t3; t3=t1+t2; t3.gettime(); 国家二级( C+)机试模拟试卷 48答案与解析 一、程序改错题( 30分)

7、 1 【正确答案】 (1)错误: 正确: ; (2)错误: ptr=p; 正确: ptr= int i=0; while (ch=getche() !=r) stri=ch; i+; stri=0; cout end1 str end1; 【试题解析】 本题考查的是考生对于基本的数据输入输出和字符数组的掌握。C+以空字符 (0)作为一个字符串的结束标志,另外本题中未涉及的常用字符串函数也是需要掌握的。 三、综合应用题( 30分) 3 【正确答案】 (1) int hours,minutes,seconds; (2) hours 0; minutes=0; (3) hours=h; (4) int h, m, s; 【试题解析】 本题主要考查考生对于类的构造函数和运算符重载的掌握。构造函数可以有一 个或多个参数,所以构造函数是可以重载的。而在类 Time运算符 “+”重载时,特别要注意重载函数要返回的是 Time型的值,而分和秒是逢 60进 1的,不是逢 100进 1或者单独相加各自的部分。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 4139-1993 Aerospace Series Screws Pan Head Offset Cruciform Recess Threaded to Head in Alloy Steel Cadmium Plated Classification 1 100 MPa (at Ambient Temperature) 235 D.pdf AECMA PREN 4139-1993 Aerospace Series Screws Pan Head Offset Cruciform Recess Threaded to Head in Alloy Steel Cadmium Plated Classification 1 100 MPa (at Ambient Temperature) 235 D.pdf
  • AECMA PREN 4139-1994 Aerospace Series Screws Pan Head Offset Cruciform Recess Threaded to Head in Alloy Steel Cadmium Plated Classification 1 100 MPa (at Ambient Temperature) 235 D.pdf AECMA PREN 4139-1994 Aerospace Series Screws Pan Head Offset Cruciform Recess Threaded to Head in Alloy Steel Cadmium Plated Classification 1 100 MPa (at Ambient Temperature) 235 D.pdf
  • AECMA PREN 4153-2009 Aerospace series Rivets solid universal head in aluminium alloy 2219 anodized or chromated metric series Edition P 1《航空航天系列.铝合金2219 万能头实心铆钉 阳极氧化或铬酸盐处理 公制系列.版本P.pdf AECMA PREN 4153-2009 Aerospace series Rivets solid universal head in aluminium alloy 2219 anodized or chromated metric series Edition P 1《航空航天系列.铝合金2219 万能头实心铆钉 阳极氧化或铬酸盐处理 公制系列.版本P.pdf
  • AECMA PREN 4154-2009 Aerospace series Rivet solid 100 degrees countersunk normal head in aluminium alloy 2219 anodized or chromated metric series Edition P1《航空航天系列.铝合金2219 100°标称埋头.pdf AECMA PREN 4154-2009 Aerospace series Rivet solid 100 degrees countersunk normal head in aluminium alloy 2219 anodized or chromated metric series Edition P1《航空航天系列.铝合金2219 100°标称埋头.pdf
  • AECMA PREN 4155-2009 Aerospace series Rivets solid 100 degrees countersunk normal head with dome in aluminium alloy 2219 anodized or chromated metric series Edition P 1《航空航天系列.铝合金2.pdf AECMA PREN 4155-2009 Aerospace series Rivets solid 100 degrees countersunk normal head with dome in aluminium alloy 2219 anodized or chromated metric series Edition P 1《航空航天系列.铝合金2.pdf
  • AECMA PREN 4157-1996 Aerospace Series Rod Ends with Self-Aligning Double Row Ball Bearings and Threaded Shank in Steel Dimensions and Loads Inch Series Edition P 1《航空航天系列.杆末端自动校准双排.pdf AECMA PREN 4157-1996 Aerospace Series Rod Ends with Self-Aligning Double Row Ball Bearings and Threaded Shank in Steel Dimensions and Loads Inch Series Edition P 1《航空航天系列.杆末端自动校准双排.pdf
  • AECMA PREN 4158-2005 Aerospace series Paints and varnishes Test method for measurements of electrical surface resistance of conductive layers Edition P 1《航空航天系列.传导层测试电表层阻抗油漆试验方法.P1.pdf AECMA PREN 4158-2005 Aerospace series Paints and varnishes Test method for measurements of electrical surface resistance of conductive layers Edition P 1《航空航天系列.传导层测试电表层阻抗油漆试验方法.P1.pdf
  • AECMA PREN 4159-2005 Aerospace series Paints and varnishes Determination of resistance to microbial growth Edition P 1《航空航天系列.微生物增长油漆阻止.P1版》.pdf AECMA PREN 4159-2005 Aerospace series Paints and varnishes Determination of resistance to microbial growth Edition P 1《航空航天系列.微生物增长油漆阻止.P1版》.pdf
  • AECMA PREN 4160-2002 Aerospace Series Non-Metallic Materials Paints and Varnishes Test Methods Determination of the Effect of Thermal Exposure Edition P 1《航空航天系列.热暴露效应非金属物质油漆测试.P1版.pdf AECMA PREN 4160-2002 Aerospace Series Non-Metallic Materials Paints and Varnishes Test Methods Determination of the Effect of Thermal Exposure Edition P 1《航空航天系列.热暴露效应非金属物质油漆测试.P1版.pdf
  • 相关搜索

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

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