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

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

1、国家二级 C+机试(操作题)模拟试卷 340及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 pmjl,此工程中包含了类 Pets(“宠物 ”)和主函数 main的定义。程序中位于每个 “ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name: sonny Type: dog Name: John Type: dog Name: Danny Type: eat Name: John Type: dog 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #inclu

2、de using namespace st: d; enllm Pets typedog, cat, bird, fish; class PetS private: char*name; Pets_type type; public: Pets(const char*flame=”sonny”, Pets_type type=dog); Pets operator=(const Pets s); Pets(); void show()const; ; Pets: Pets(const char*name, Pets type type) /构造函数 this-name=new charstrl

3、en (name)+1; strcpy(this一 name, name); ERROR*found* type=type; Pets: Pets()析构函数,释放 name 所指向的字符串 ERROR*found* name= 0; Pets DiscountSale: DiscountSale ( ): discount(0) DiScountSale: DiscountSale(double the_price, double the_discount) : Sale(the_price), discount(the discount) double DiscountSale: bill

4、)const double fraction=discount 100 ; *found* _;返回本对象打折以 后的实际售价 bool operator using namespace std; template class Array数组类 public: Array(Type b, int mm) 构造 函数 for(int i=0; i=m) cout void Array: Contrary() 补充函数体 *333* *666* int main() int sl5=1, 2, 3, 4, 5; double s26=1 2, 2 3, 3 4, 4 5, 5 6, 8 4);

5、Arraydl(s1, 5); Arrayd2(s2, 6); int i; d1 Contrary(); d2 Contrary(); couttype=type; (2)deletenal le; (3)strepy(this-nanle, s name); 【试题解析】 (1)主要考查考生对构造函数的掌握情况,因为形参名和类的私有成员名称都是 type,为了避免混淆,所以规定类的私有成员使用 this指针调用,即: this一 type=type;。 (2)主要考查考生对析构函数的掌握情况,题目中要求,释放 name所指向的字符串。要释放 name指针用 delete语句,即 delet

6、ename;。 (3)主要考查考生对 strepy函数的掌握情况, strcpy函数的形参为两个字符串,而 name为指向字符串的指针,因此使用语句: strcpy(this一 nallle, s name); . 二、简单应用题 2 【正确答案】 (1)return this-bill()-other bill() (2)return fraction*price (3)return first bill()bill()一 other bill() 同样, this指针引用当前对象, other是引用对象,所以可以与 bill()虚函数一起使用多态机制,获得当前对象和 other对象的实际价格,再进行差值计算 (4)main()函数中,程序判断 discount小于 simple后,输出提示信息,再调用savings()函数输出 discount和 simple的差值,这里需要计算 discount比 simple节省多少钱,所以需要将 simple当做当前对象, discount当做参数传人 savings()函数,所以补充语句如下: simple savings(discount) 三、综合应用题 3 【正确答案】 for(int i=0, j =m一 1; ij时停止交换即可。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 3508-1998 Aerospace Series Steel FE-PL1501 (30CrMo12) Air Melted Hardened and Tempered Bar De Less Than or Equal to 100 mm 930 MPa Less Than or Equal to Rm Less Than or .pdf AECMA PREN 3508-1998 Aerospace Series Steel FE-PL1501 (30CrMo12) Air Melted Hardened and Tempered Bar De Less Than or Equal to 100 mm 930 MPa Less Than or Equal to Rm Less Than or .pdf
  • AECMA PREN 3509-1998 Aerospace Series Steel FE-PL1501 (30CrMo12) Air Melted Hardened and Tempered Bar De Less Than or Equal to 40 mm 1 050 MPa Less Than or Equal to Rm Less Than or.pdf AECMA PREN 3509-1998 Aerospace Series Steel FE-PL1501 (30CrMo12) Air Melted Hardened and Tempered Bar De Less Than or Equal to 40 mm 1 050 MPa Less Than or Equal to Rm Less Than or.pdf
  • AECMA PREN 3510-1997 Aerospace Series Heat Resisting Steel FE-PA2602 (X4NiCrTiMoV26-15) Solution Treated and Precipitation Treated Bar and Section De Less Than or Equal to 100 mm E.pdf AECMA PREN 3510-1997 Aerospace Series Heat Resisting Steel FE-PA2602 (X4NiCrTiMoV26-15) Solution Treated and Precipitation Treated Bar and Section De Less Than or Equal to 100 mm E.pdf
  • AECMA PREN 3511-1999 Aerospace Series Steel FE-PL1801 (100Cr6) Vacuum Induction Melted and Consumable Electrode Remelted Softened Bar for the Manufacture of Machined Bearings a or .pdf AECMA PREN 3511-1999 Aerospace Series Steel FE-PL1801 (100Cr6) Vacuum Induction Melted and Consumable Electrode Remelted Softened Bar for the Manufacture of Machined Bearings a or .pdf
  • AECMA PREN 3512-1999 Aerospace Series Steel FE-PL1801 (100Cr6) Vacuum Induction Melted and Consumable Electrode Remelted Hardened and Tempered Hollow Bars for the Manufacture of Beo.pdf AECMA PREN 3512-1999 Aerospace Series Steel FE-PL1801 (100Cr6) Vacuum Induction Melted and Consumable Electrode Remelted Hardened and Tempered Hollow Bars for the Manufacture of Beo.pdf
  • AECMA PREN 3513-1988 Aerospace Series Steel FE-PL711 Hardened and Tempered 900 Less Than or Equal to Rm Less Than or Equal to 1100 MPa Bar and Wire De Less Than or Equal to 45 mm I.pdf AECMA PREN 3513-1988 Aerospace Series Steel FE-PL711 Hardened and Tempered 900 Less Than or Equal to Rm Less Than or Equal to 1100 MPa Bar and Wire De Less Than or Equal to 45 mm I.pdf
  • AECMA PREN 3514-1988 Aerospace Series Steel FE-PL711 Hardened and Tempered 1100 Less Than or Equal to Rm Less Than or Equal to 1300 MPa Bar and Wire for Bolts De Less Than or Equal.pdf AECMA PREN 3514-1988 Aerospace Series Steel FE-PL711 Hardened and Tempered 1100 Less Than or Equal to Rm Less Than or Equal to 1300 MPa Bar and Wire for Bolts De Less Than or Equal.pdf
  • AECMA PREN 3515-1998 Aerospace Series Steel FE-PL8201 (41NiCrMo2) Air Melted Hardened and Tempered Forgings De Less Than or Equal to 25 mm 1 100 MPa Less Than or Equal to Rm Less T.pdf AECMA PREN 3515-1998 Aerospace Series Steel FE-PL8201 (41NiCrMo2) Air Melted Hardened and Tempered Forgings De Less Than or Equal to 25 mm 1 100 MPa Less Than or Equal to Rm Less T.pdf
  • AECMA PREN 3516-1998 Aerospace Series Steel FE-PL8201 (41NiCrMo2) Air Melted Softened Forging Stock a or D Less Than or Equal to 300 mm Edition P2《航空航天系列.钢FE-PL8201(41NiCrMo2) 空气熔炼.pdf AECMA PREN 3516-1998 Aerospace Series Steel FE-PL8201 (41NiCrMo2) Air Melted Softened Forging Stock a or D Less Than or Equal to 300 mm Edition P2《航空航天系列.钢FE-PL8201(41NiCrMo2) 空气熔炼.pdf
  • 相关搜索

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

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