欢迎来到麦多课文档分享! | 帮助中心 海量文档,免费浏览,给你所需,享你所想!
麦多课文档分享
全部分类
  • 标准规范>
  • 教学课件>
  • 考试资料>
  • 办公文档>
  • 学术论文>
  • 行业资料>
  • 易语言源码>
  • ImageVerifierCode 换一换
    首页 麦多课文档分享 > 资源分类 > DOC文档下载
    分享到微信 分享到微博 分享到QQ空间

    【计算机类职业资格】二级C++分类模拟132及答案解析.doc

    • 资源ID:1324209       资源大小:51.50KB        全文页数:9页
    • 资源格式: DOC        下载积分:5000积分
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    二维码
    微信扫一扫登录
    下载资源需要5000积分(如需开发票,请勿充值!)
    邮箱/手机:
    温馨提示:
    如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如需开发票,请勿充值!如填写123,账号就是123,密码也是123。
    支付方式: 支付宝扫码支付    微信扫码支付   
    验证码:   换一换

    加入VIP,交流精品资源
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    【计算机类职业资格】二级C++分类模拟132及答案解析.doc

    1、二级 C+分类模拟 132 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程中包含程序文件 main.cpp,其中有 ElectricFan(“电风扇”)类和主函数 main 的定义。程序中位于每个“/ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 品牌:清风牌,电源:关,风速:0 品牌:清风牌,电源:开,风速:3 品牌:清风牌,电源:关,风速:0 注意:只修改每个“/ ERROR *found*”下的那一行,不要改

    2、动程序中的其他内容。 #include iostream using namespace std; class ElectricFan /“电扇”类 char * brand; int intensity; /风速:0-关机,1-弱,2-中,3-强 public: ElectricFan(const char * the_brand): intensity(0) brand = new charstrlen (the_brand) +1; strcpy(brand, the brand); ElectricFan() delete brand; / ERROR *found* const ch

    3、ar * theBrand() const return * brand; /返回电扇品牌 int theIntensity() const return intensity; /返回风速 bool isOn() const return intensity0; /返回电源开关状态 / ERROR *found* void turnOff() intensity=1; /关电扇 void setIntensity (int inten) /开电扇并设置风速 / ERROR *found* if (intensity = 1 void show() cout “品牌:“ theBrand() “

    4、牌“ “,电源:“ (isOn()? “开“:“关“) “,风速:“ theIntensity() endl; ; int main() ElectricFan fan (“清风“); fan.show(); fan.setIntensity(3); fan.show(); fan.turnOff(); fan.show(); return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,该工程中包含一个程序文件 main.cpp,其中有类 AutoMobile(“汽车”)及其派生类 Car

    5、(“小轿车”)、Truck(“卡车”)的定义,还有主函数main 的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:车牌号:冀 ABC1234 品牌:ForLand 类别:卡车当前档位:0 最大载重量:12 车牌号:冀 ABC1234 品牌:ForLand 类别:卡车当前档位:2 最大载重量:12 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档位:0 座位数:5 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档位:-1 座位数:5 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/ *found*”。

    6、 #include iostream #include iomanip #include cmath using namespace std; class AutoMobile /“汽车”类 char * brand; /汽车品牌 char * number; /车牌号 int speed; /档位 1、2、3、4、5,空档:0,倒挡:-1 public: AutoMobile(const char * the_brand, const char * the_number): speed(0) brand = new charstrlen (the_brand) +1; / *found* _

    7、; / *found* _; strcpy (number, the number); AutoMobile _ delete brand; delete number; const char * theBrand _ const return brand; /返回品牌名称 const char * theNumber _ const return number; /返回车牌号 int currentSpeed _ const return speed; /返回当前档位 void changeGearTo (int the_speed) /换到指定档位 if (speed = -1 virtu

    8、al const char * category _ const =0; /类别:卡车、小轿车等 virtual void show _ const cout “车牌号:“ theNumber _ / *found* “品牌:“ “类别:“ category _ “当前档位:“ currentSpeed _ ; ; class Car: public AutoMobile int seats; /座位数 public: Car (const char * the_brand, const char * the_number, int the_seats): AutoMobile (the_br

    9、and, the_number), seats (the_seats) int numberOfSeat _ const return seats; /返回座位数 const char * category _ const return “小轿车“; /返回汽车类别 void show _ const AutoMobile:show _ ; cout “座位数:“ numberOf Seat _ endl; ; class Truck: public AutoMobile /“卡车”类 int max_load; /最大载重量 public: Truck (const char * the_b

    10、rand, const char * the_number, int the_max_load): AutoMobile (the_brand, the_number), max_load(the_max_load) int maxLoad _ const return max_load; /返回最大载重量 / *found* const char * category _ _ /返回汽车类别 void show _ const AutoMobile:show _ ; cout “最大载重量:“ maxLoad _ endl; ; int main _ Truck truck (“ForLan

    11、d“,“冀 ABC1234“, 12); truck.show _ ; truck.changeGearTo(2); truck.show _ ; Car car (“QQ“, “沪 XYZ5678“,5); car.show _ ; car.changeGearTo(-1); car.show _ ; cout endl; return 0; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程 proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于 1 的最小公因子。请编写友员函数 FriFu

    12、n,使其输出结果为: Common denominator is 2 要求:补充编制的内容写在“/ *333*”与“/ *666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。 /proj3.h class FriFunClass int a, b; public: FriFunClass (int i, int j) a=i; b=j; friend int FriFun (FriFun- Class x); /友元函数 ; void writeToFile (const

    13、char *); /proj3.cpp #include iostream using namespace std; #include “prj3.h“ int FriFun (FriFunClass x) / *333* /由于函数 FriFun()是类 FriFunClass 的友元函数,所以它可以直接访问 a 和 b / *666* int main() FriFunClass n(10, 20); if (FriFun(n) cout “Common denominator is“ FriFun(n) “/n“; else cout “No common denominator./n“

    14、; writeToFile(“ “); return 0; (分数:40.00)_二级 C+分类模拟 132 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程中包含程序文件 main.cpp,其中有 ElectricFan(“电风扇”)类和主函数 main 的定义。程序中位于每个“/ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 品牌:清风牌,电源:关,风速:0 品牌:清风牌,电源:开,风速:3 品牌:清风牌,电源:关

    15、,风速:0 注意:只修改每个“/ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class ElectricFan /“电扇”类 char * brand; int intensity; /风速:0-关机,1-弱,2-中,3-强 public: ElectricFan(const char * the_brand): intensity(0) brand = new charstrlen (the_brand) +1; strcpy(brand, the brand); ElectricFan(

    16、) delete brand; / ERROR *found* const char * theBrand() const return * brand; /返回电扇品牌 int theIntensity() const return intensity; /返回风速 bool isOn() const return intensity0; /返回电源开关状态 / ERROR *found* void turnOff() intensity=1; /关电扇 void setIntensity (int inten) /开电扇并设置风速 / ERROR *found* if (intensity

    17、 = 1 void show() cout “品牌:“ theBrand() “牌“ “,电源:“ (isOn()? “开“:“关“) “,风速:“ theIntensity() endl; ; int main() ElectricFan fan (“清风“); fan.show(); fan.setIntensity(3); fan.show(); fan.turnOff(); fan.show(); return 0; (分数:30.00)_正确答案:()解析:(1)const char*theBrand() const return brand; /返回电扇品牌 (2)void tur

    18、nOff() intensity=0; /关电扇 (3)if(inten=1 class AutoMobile /“汽车”类 char * brand; /汽车品牌 char * number; /车牌号 int speed; /档位 1、2、3、4、5,空档:0,倒挡:-1 public: AutoMobile(const char * the_brand, const char * the_number): speed(0) brand = new charstrlen (the_brand) +1; / *found* _; / *found* _; strcpy (number, th

    19、e number); AutoMobile _ delete brand; delete number; const char * theBrand _ const return brand; /返回品牌名称 const char * theNumber _ const return number; /返回车牌号 int currentSpeed _ const return speed; /返回当前档位 void changeGearTo (int the_speed) /换到指定档位 if (speed = -1 virtual const char * category _ const

    20、=0; /类别:卡车、小轿车等 virtual void show _ const cout “车牌号:“ theNumber _ / *found* “品牌:“ “类别:“ category _ “当前档位:“ currentSpeed _ ; ; class Car: public AutoMobile int seats; /座位数 public: Car (const char * the_brand, const char * the_number, int the_seats): AutoMobile (the_brand, the_number), seats (the_seat

    21、s) int numberOfSeat _ const return seats; /返回座位数 const char * category _ const return “小轿车“; /返回汽车类别 void show _ const AutoMobile:show _ ; cout “座位数:“ numberOf Seat _ endl; ; class Truck: public AutoMobile /“卡车”类 int max_load; /最大载重量 public: Truck (const char * the_brand, const char * the_number, in

    22、t the_max_load): AutoMobile (the_brand, the_number), max_load(the_max_load) int maxLoad _ const return max_load; /返回最大载重量 / *found* const char * category _ _ /返回汽车类别 void show _ const AutoMobile:show _ ; cout “最大载重量:“ maxLoad _ endl; ; int main _ Truck truck (“ForLand“,“冀 ABC1234“, 12); truck.show _

    23、 ; truck.changeGearTo(2); truck.show _ ; Car car (“QQ“, “沪 XYZ5678“,5); car.show _ ; car.changeGearTo(-1); car.show _ ; cout endl; return 0; (分数:30.00)_正确答案:()解析:(1)strcpy(brand,the_brand) (2)number=new charstrlen(the_number)+1 (3)theBrand() (4)const return “卡车“; 答案考生文件夹 考点 本题考查的是 AutoMobile 类及其派生类

    24、Car 类和 Truck 类,其中涉及动态数组、构造函数、strcpy()函数、析构函数、纯虚函数和虚函数。本题程序较多,基类较复杂,但细心看会发现程序很容易读,考的知识点都很简单,和前后语句一对比就可以得到答案。 解析 (1)主要考查考生对 strcpy 函数的掌握情况,在上一条语句程序给 brand 指针分配了空间,在这里要复制字符串 the_brand,即 strcpy(brand,the_brand);。 (2)主要考查考生对动态分配的掌握情况,参考 brand 指针的复制过程完成该语句,先给指针 number 分配空间,通过 new 来完成:number=new charstrlen

    25、(the_number)+1;。 (3)主要考查考生对成员函数的掌握,由程序可知这里要输出的是品牌,因此调用成员函数 theBrand()来输出品牌。 (4)主要考查考生对纯虚函数的掌握,根据纯虚函数的定义:virtual const char*category()const=0;,可知在这里要填写:constreturn“卡车“;。三、综合应用题(总题数:1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程 proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于 1 的最小公因子。请编写友员函数 FriFun,使其输出结果为: Common

    26、 denominator is 2 要求:补充编制的内容写在“/ *333*”与“/ *666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。 /proj3.h class FriFunClass int a, b; public: FriFunClass (int i, int j) a=i; b=j; friend int FriFun (FriFun- Class x); /友元函数 ; void writeToFile (const char *); /proj3.c

    27、pp #include iostream using namespace std; #include “prj3.h“ int FriFun (FriFunClass x) / *333* /由于函数 FriFun()是类 FriFunClass 的友元函数,所以它可以直接访问 a 和 b / *666* int main() FriFunClass n(10, 20); if (FriFun(n) cout “Common denominator is“ FriFun(n) “/n“; else cout “No common denominator./n“; writeToFile(“ “

    28、); return 0; (分数:40.00)_正确答案:()解析:int min = x.a x.b ? x.a : x.b; /此处为取出 x.a 与 x.b 中的最小值 for (int i = 2; i = min; i+) /从 i 到 min 遍历数组 if (x.a% i = 0 return -1; 答案考生文件夹 考点 本题考查的是 FriFunClass 类,其中涉及构造函数和友元函数。题目要求完成友元函数,在函数体内可以任意调用 FriFunClass 类的私有成员。 解析 主要考查考生对友元函数的掌握情况,友元函数可以访问类的私有数据成员,题目要求函数求出两个数据成员的大于 1 的最小公因子,从 2 开始往上算,因此要同时可以被两个私有成员整除,这里用取余符号完成,取余为 0 即为整除。 主要考查考生对友元函数的掌握情况,友元函数可以访问类的私有数据成员。


    注意事项

    本文(【计算机类职业资格】二级C++分类模拟132及答案解析.doc)为本站会员(cleanass300)主动上传,麦多课文档分享仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文档分享(点击联系客服),我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

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

    收起
    展开