ImageVerifierCode 换一换
格式:DOC , 页数:8 ,大小:36.50KB ,
资源ID:497373      下载积分:2000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-497373.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文([计算机类试卷]国家二级C++机试(操作题)模拟试卷297及答案与解析.doc)为本站会员(刘芸)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

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

1、国家二级 C+机试(操作题)模拟试卷 297及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,此工程中包含程序文件 main cpp,其中有 ElectricFan(“电风扇 ”)类和主函数 main的定义。程序中位于每个 “ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 品牌:清风牌,电源:关,风速: 0 品牌:清风牌,电源:开,风速: 3 品牌:清风牌,电源:关,风速: 0 注意:只修改每个 “ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include i

2、ostream using namespace std; class ElectricFan “电扇 ”类 char * brand; int intensity; 风速: 0关机, 1弱, 2中, 3强 public: ElectricFan fconst char * the_brand): intensity(0) brand new charstrlen(the_brand) 1; strcpy(brand, the_brand); ElectricFan()deletebrand; ERROR *found* const char * theBrand()constreturn *

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

4、 “ (isOn()?“开 “: “关 “) “,风速: “ theIntensity() endl; ; int mein() ElectricFan fan(“清风 “); fan show(); fan setIntensity(3); fan show(); fan turnOff(); fan show(); return 0; 二、简单应用题 2 请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2,该工程中 包含一个程序文件 main epp,其中有类 AutoMobile(“汽车 ”)及其派生类 Car(“小轿车 ”)、 Truck(“卡车 ”)的定义

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

6、#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* _; *found* _; strcpy(n

7、umber,the_number); AutoMobile() deletebrand; deletenumber; const char * theBrand()constreturn brand; 返回品牌名称 const char *theNumber() constreturn number; ) 返回车牌号 int currentSpeed()constreturn speed; ) 返回当前档位 void changeGearTo(int the speed) 换到指定档位 if(speed 1 speed 5) speed the_speed; virtual const cha

8、r * 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, intthe_seats):AutoMobile(the_brand, the_number), s

9、eats(the_seats) int numberOfSeat()constreturn seats; 返回座位数 const char * category()const return“小轿车 “; 返回汽车类别 void show()const AutoMobile show(); cout “座位数: “ number OfSeat() end1; ; class Truck: public AutoMobile “卡车 ”类 int max_load;最大载重量 public: Truck(const char * the_brand, const char * the_number

10、, int the_max_load):AutoMobile(the_brand, the_number), max_load(the_max load) int maxLoad()constreturn max_load; )返回最大载重量 *found* const char * category() _返回汽车类别 void show()const AutoMobile show(); cout “最大载重量: “ maxLoad() end1; ; int main() Truck truck(“ForLand“, “冀 ABC1234”, 12), truck show(); tru

11、ck changeGearTo(2); truck show(); Car car(“QQ“, “沪 XYZ5678“, 5); car show(); car changeGearTo( 1); car show(); cout endl; return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于 1的最小公因子。请编写友员函数 FriFun,使其输出结果为: Common denominator is 2 要求:补充编制的内容写在 “ *333*”与 “*666*”之

12、间,不得修改程 序的其他部分。 注意:程序最后将结果输出到文件 out dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。 proj3 h C1ass FriFunClaSS int a, b; public: FriFunClass(int i, int J)a i; b j; friend int FriFun(FriFunClass x); 友元函数 ; void writeToFile(const char *); proj3 cpp #include iostream using namespace std; #include“prj3 h“ in

13、t 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(“); return 0; 国家二级 C+机试(操作题)模拟试卷 297答案与解析 一、基本操作题 1 【正确答案】 (1)const char * t

14、heBrand()constretumbrand; 返回电扇品牌 (2)void turnOff()intensity 0; 关电扇 (3)if(inten 1 inten 3)intensity inten: 【试题解析】 (1)主要考查考生对指针的掌握情况,因为 brand是一个动态指针,木 brand表示字符串的首个字符, brand表示动态数组,这里要返回动态数组存储的品牌名称。 (2)主要考查考生对成员函数的掌握情况,根据题目中类的定义中私有成员的定义: int intensity;风速: 0关机, 1弱, 2中, 3强,可知本函数要关电扇,因此在这里 intensity 0;。 (

15、3)主要考查考生对成员函数的掌握,根据题 目中函数的注释:开电扇并设置风速,可知 if语句里要判断的应该是形参 inten而不是 intensity。 二、简单应用题 2 【正确答案】 (1)strcpy(brand, the_brand) (2)number new charstrlen(the_number) 1 (3)theBrand() (4)constreturn“卡车 “; 【试题解析】 (1)主要考查考生对 strcpy函数的掌握情况,在上一条语句程序给brand指针分配了空间,在这里要复制字符串 the_brand,即 strcpy(brand,the_brand);。 (2)

16、主要考查考生对动态分配的掌握情况,参考 brand指针的复制过程完成该语句,先给指针 number分配空间,通过 new来完成: number new charstrlen(the_number) 1;。 (3)主要考查考生对成员函数的掌握,由程序可知这里要输出的是品牌,因此调用成员函数 theBrand()来输出品牌。 (4)主要考查考生对纯虚函数的掌握,根据纯虚函数的定义: virtual const char * category()const 0;,可知在这里要填写: constreturn“卡车 “; 。 三、综合应用题 3 【正确答案】 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 x b i 0) 如 i能同时整除 x a来的 x b,则仅回 i return i; return 1; 【试题解析】 主要考查考生对友元函数的掌握情况, 友元函数可以访问类的私有数据成员,题目要求函数求出两个数据成员的大于 1的最小公因子,从 2开始往上算,因此要同时可以被两个私有成员整除,这里用取余符号完成,取余为 0即为整除。

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