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

    【计算机类职业资格】国家二级C++机试(操作题)模拟试卷330及答案解析.doc

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

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

    【计算机类职业资格】国家二级C++机试(操作题)模拟试卷330及答案解析.doc

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

    2、不要改动程序中的其他内容。#includeiostreamusing namespace std;class ElectricFan “电扇”类 char*brand; int intensity; 风速:0 一关机,1 一弱,2 一中,3 一强 public: ElectricFan(const char*thebrand):intensity(0) brand=new charstrlen(the brand)+1 ; strcpy(brand,the_brand); 一ElectricFan()deletebrand;)ERROR*found* const char*theBrand()

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

    4、)?”开”:”关”) ”,风速:”theIntensity()end1; ; int main() ElectricFan fan(”清风”); fanshow(); fansetIntensity(3); fanshow(); fanturnOff(); fanshow(); return 0; (分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj2 下的工程 proj2,其中定义了 vehicle 类,并派生出 motorcar 类和 bicycle 类。然后以 motorcar 和 bicyele 作为基类,再派生

    5、出 motorcycle 类。要求将 vehicle 作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 80 150 100 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“*found*”。#includeiostreamhclasS vehicleprivate: int MaxSpeed; int Weight;public:*found* vehicle (int maxspeed, int weight):_ 一 vehicle(); int getMaxSpeed() return

    6、 MaxSpeed;) int getWeight()return Weight;) ; *found* class bicycle:_public vehicle private: int Height;public: bicycle(int maxspeed,int weight,int height):vehicle (maxspeed,weight),Height(height) int getHeight()return Height; ; *found* class motorcar:_public vehicle private: int SeatNum;public: moto

    7、rcar(int maxspeed,int weight int seatnum):vehicle (maxspeed weight),SeatNum(seatnum)f) int getSeatNum()return SeatNum;); ; * found* class motorcycle :_ public: motorcycle (int maxspeed, in weight,int height):vehicle(ma,speed,weight),bicycle(maxspeed weight,height),motorcar(maxspeed weight,1);,void m

    8、ain() motorcycle a(80,150,100); coutagetMaxSpeed()endl; coutagetWeight()endl; coutagetHeight()endl; coutagetSeatNum()endl; (分数:2.00)_三、综合应用题(总题数:1,分数:2.00)3.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj3 下的工程 proj3,其中包含了类 Integers 和主函数 main 的定义。一个 Integers 对象就是一个整数的集合,其中包含 0 个或多个可重复的整数。成员函数 add 的作用是将一个元素添加到集合中,成员函数

    9、 remove 的作用是从集合中删除指定的元素(如果集合中存在该元素),成员函数 sort 的作用是将集合中的整数按升序进行排序。请编写这个 sort 函数。此程序的正确输出结果应为: 5 28 2 4 5 3 2 75 27 66 31 5 28 2 4 5 3 2 75 27 66 31 6 5 28 2 4 5 3 2 75 27 66 31 6 19 5 28 4 5 3 2 75 27 66 31 6 19 5 28 4 5 3 2 75 27 66 31 6 19 4 2 3 4 4 5 5 6 19 27 28 31 66 75 要求: 补充编制的内容写在“*333*”与“*66

    10、6*”之间。不得修改程序的其他部分。 注意:相关文件包括:maincpp、Integersh。 程序最后调用 writeToFile 函数,使用另一组不同的测试数据,将不同的运行结果输出到文件 outdat 中。输出函数 writeToFile 已经编译为 obi 文件。Integersh#ifndef INTEGERS#define INTEGERS#includeiostreamusing namespace std;const int MAXELEMENTS=100;集合最多可拥有的元素个数 class Integersint e lemMAXELEMENTS;用于存放集合元素的数组 i

    11、nt counter;用于记录集合中元素个数的计数器 public: Integers():counter(0)创建一个空集合 Integers(int data,int size);利用数组提供的数据创建一个整数集合 void add(int element);添加一个元素到集合中 void remove(int element);删除集合中指定的元素 int getCount()constreturn counter;返回集合中元素的个数 int getElement(int i)constreturn elemi;)返回集合中指定的元素 void sort();将集合中的整数按由小到大的

    12、次序进行排序 void show()const;显示集合中的全部元素;void writeToFile(const char*path);#endifmaincpp#include”Integersh”#includeiomanipIntegers:Integers(int data,int Size):counter(0) for(int i=0;iSize;i+)add(da-tai);void Integers:add(int element) if(counterMAXELEMENTS) elemcounter+=element; void Integers:remove(int el

    13、ement) int j; for(j=counter 一1;j=0;j 一一) if(elemj=element)break; for(int i=j;icounter 一 1;i+) elemi=elemi+1; counter 一一; void Integers:sort()*333*666*void Integers:show()const for(int i=0;iget;Count();i+) coutsetw(4)getElement(i); coutendl;int main() int d=5,28,2,4,5,3,2,75,27,66,31); Integers S(d,1

    14、1); Sshow(); Sadd(6); Sshow(); Sadd(19); Sshow(); sEemove(2); sshow(); sadd(4); sshow(); ssort;(); sshow(); writeTOFile(”); return 0;(分数:2.00)_国家二级 C+机试(操作题)模拟试卷 330 答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj1 下的工程 proj1,此工程中包含程序文件maincpp,其中有 ElectricFan(“电风扇”)类和主函

    15、数 main 的定义。程序中位于每个“ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: 品牌:清风牌,电源:关,风速:0 品牌:清风牌,电源:开,风速:3 品牌:清风牌,电源:关,风速:0 注意:只修改每个“ERROR*found*”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class ElectricFan “电扇”类 char*brand; int intensity; 风速:0 一关机,1 一弱,2 一中,3 一强 public: ElectricFan(const char*the

    16、brand):intensity(0) brand=new charstrlen(the brand)+1 ; strcpy(brand,the_brand); 一ElectricFan()deletebrand;)ERROR*found* const char*theBrand()constreturn*brand;) 返回电扇品牌 int theIntensity()const return intensity;)返回风速 boo1 isOn()constreturn intensity0;返回电源开关状态ERROR*found* void turnOff()intensity=1;)关电

    17、扇 void setIntensity(int inten)开电扇并设置风速ERROR*found* if(intensity=1intensity=3) intensity=inten; void show() cout“品牌:“theBrand()”牌” ”,电源:”(isOn()?”开”:”关”) ”,风速:”theIntensity()end1; ; int main() ElectricFan fan(”清风”); fanshow(); fansetIntensity(3); fanshow(); fanturnOff(); fanshow(); return 0; (分数:2.00

    18、)_正确答案:(正确答案:(1)const char*theBrand()constreturn brand; 返回电扇品牌 (2)void turnOff()intensity=0;关电扇 (3)if(inten=l,void main() motorcycle a(80,150,100); coutagetMaxSpeed()endl; coutagetWeight()endl; coutagetHeight()endl; coutagetSeatNum()endl; (分数:2.00)_正确答案:(正确答案:(1)MaxSpeed(maxspeed),Weight(weight); (2

    19、)virtual (3)virtual (4)public bicycle,public motorcar)解析:解析:(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员 MaxSpeed 和Weight 初始化。 (2)主要考查考生对派生类的掌握,题目要求将 vehicle 作为虚基类,避免二义性问题。因此在这里添加 virtual 使 vehicle 成为虚基类。 (3)主要考查考生对派生类的掌握,题目要求以motorcar 和 bicycle 作为基类,再派生出 motorcycle 类。在主函数中可以看到 motorcycle 类的实例 a调用 getHeiglt

    20、函数和 getSeatNum 函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。三、综合应用题(总题数:1,分数:2.00)3.请使用 VC6 或使用【答题】菜单打开考生文件夹 proj3 下的工程 proj3,其中包含了类 Integers 和主函数 main 的定义。一个 Integers 对象就是一个整数的集合,其中包含 0 个或多个可重复的整数。成员函数 add 的作用是将一个元素添加到集合中,成员函数 remove 的作用是从集合中删除指定的元素(如果集合中存在该元素),成员函数 sort 的作用是将集合中的整数按升序进

    21、行排序。请编写这个 sort 函数。此程序的正确输出结果应为: 5 28 2 4 5 3 2 75 27 66 31 5 28 2 4 5 3 2 75 27 66 31 6 5 28 2 4 5 3 2 75 27 66 31 6 19 5 28 4 5 3 2 75 27 66 31 6 19 5 28 4 5 3 2 75 27 66 31 6 19 4 2 3 4 4 5 5 6 19 27 28 31 66 75 要求: 补充编制的内容写在“*333*”与“*666*”之间。不得修改程序的其他部分。 注意:相关文件包括:maincpp、Integersh。 程序最后调用 writeT

    22、oFile 函数,使用另一组不同的测试数据,将不同的运行结果输出到文件 outdat 中。输出函数 writeToFile 已经编译为 obi 文件。Integersh#ifndef INTEGERS#define INTEGERS#includeiostreamusing namespace std;const int MAXELEMENTS=100;集合最多可拥有的元素个数 class Integersint e lemMAXELEMENTS;用于存放集合元素的数组 int counter;用于记录集合中元素个数的计数器 public: Integers():counter(0)创建一个空

    23、集合 Integers(int data,int size);利用数组提供的数据创建一个整数集合 void add(int element);添加一个元素到集合中 void remove(int element);删除集合中指定的元素 int getCount()constreturn counter;返回集合中元素的个数 int getElement(int i)constreturn elemi;)返回集合中指定的元素 void sort();将集合中的整数按由小到大的次序进行排序 void show()const;显示集合中的全部元素;void writeToFile(const cha

    24、r*path);#endifmaincpp#include”Integersh”#includeiomanipIntegers:Integers(int data,int Size):counter(0) for(int i=0;iSize;i+)add(da-tai);void Integers:add(int element) if(counterMAXELEMENTS) elemcounter+=element; void Integers:remove(int element) int j; for(j=counter 一1;j=0;j 一一) if(elemj=element)bre

    25、ak; for(int i=j;icounter 一 1;i+) elemi=elemi+1; counter 一一; void Integers:sort()*333*666*void Integers:show()const for(int i=0;iget;Count();i+) coutsetw(4)getElement(i); coutendl;int main() int d=5,28,2,4,5,3,2,75,27,66,31); Integers S(d,11); Sshow(); Sadd(6); Sshow(); Sadd(19); Sshow(); sEemove(2);

    26、 sshow(); sadd(4); sshow(); ssort;(); sshow(); writeTOFile(”); return 0;(分数:2.00)_正确答案:(正确答案:for(int i=0;icounter;i+) 遍历数组 elem for(int j=counter 一1;ji;j -) 从最后一位到 i 到前一位遍历 elem if(elemielemj) 如果 elemi大于elemj,则两值替换 int temp=elemi; 定义整形变量 temp 并赋值为 elemi; elemi=elemj; 给 elemi赋值 elemi elemj=temp; 给 elemj赋值 temp )解析:解析:主要考查考生对排序算法的掌握,要排序的数组为 elem,元素个数为 counter,在这里使用下标 i 和 j 进行比较,当 elemielemj时,数组元素通过中间变量 temp 进行交换。


    注意事项

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




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

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

    收起
    展开