【计算机类职业资格】国家二级C++机试(操作题)模拟试卷330及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷330及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷330及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
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
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 330 答案 解析 DOC
