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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

【计算机类职业资格】二级C++-73 (1)及答案解析.doc

1、二级 C+-73 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,其中包含类 Myaass的定义。程序中位于每个“/ERROR *found*”下的一行语句有错误,请加以更正。更正后程序的输出结果应该是: The value is 5 The value is 10 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class MyCla

2、ss public: / ERROR * found* voidMyClass() value = 0; / ERROR * found* void setValue(int val) const value=val; int getValue() const return value; private: /ERROR *found* int value=0; ; int main() MyClass obj; obj.setValue(5); cout “The value is“ obj. getValue() endl; obj.setValue(10); cout “The value

3、 is“ obj. getValue() endl; return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2,其中定义了 vehicle类,并派生出 motorcar类和 bicycle类。然后以 motorcar和 bicycle作为基类,再派生出 motocycle类。要求将vehicle作为虚基类,避免二义性问题。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: A vehicle is running! A vehicle has sto

4、pped! A bicycle is running! A bicycle has stopped! A motorcar is running! A motocycle is running! 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream.h class vehicle private: int MaxSpeed; int Weight; public: vehicle(): MaxSpeed(0), Weight(0) vehicle(int max_speed, int weight): MaxSpe

5、ed (max_speed ), Weight (weight)( /* found* _Run() cout “Avehicle is running!“ endl; /* found* _Stop() cout “A vehicle has stopped!“ endl; ; class bicycle : virtual public vehicle private: int Height; public: bicycle(): Height(0) bicycle(int max_speed, int weight,int height) :vehicle (max_speed, wei

6、ght), Height(height); void Run () cout “A bicycle isrunning!“ endl; void Stop() cout “Abicycle hasstopped!“ endl; ; class motorcar : virtual public vehicle private: int SeatNum; public: motorcar(): SeatNum(0) motorcar (int max_speed, intweight, int seat_num) /* found* :_ void Run() cout “A motorcar

7、isrunning!“ endl; void Stop () cout “A motorcarhas stopped!“ endl; ; /* found* class motorcycle: _ public: motorcycle() motorcycle (int max_speed, int weight, int height, int seet_num):bicycle(max_speed, weight, height), motorcar (max_speed, weight, seet_num); motorcycle () ; void Run () cout “A mot

8、orcycle is running!“ endl; void Stop() cout “A motorcycle has stopped!“ endl; ; int main() vehicle * ptr; vehicle a; bicycle b; motorcar c; motorcycle d; a.Run(); a. Stop(); b.Run(); b. Stop(); ptr = ptr-Run(); ptr = ptr-Run(); return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 p

9、roj3下的工程 proj3,其中定义的 IntArray是一个用于表示整型一维数组的类。成员函数 swap可以将数组中的两个指定元素交换位置;成员函数 sort的功能是将数组元素按照升序排序。请编写成员函数 sort。在 main函数中给出了一组测试数据,此时程序运行中应显示: 读取输入文件 -排序前- a1=3 1 2 a2=5 2 7 4 1 6 3 -排序后- a1=1 2 3 a2=1 2 3 4 5 6 7 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat中。输出函数 WriteToFile已

10、经编译为 obj文件,并且在本程序中调用。 /IntArray.h #include iostream #include string.h using namespace std; class IntArray public: IntArray(unsigned int n) size = n; data = new intsize; IntArray() delete data; int getSize() const return size; int void swap(int i, int j) int temp = datai; datai = dataj; dataj = temp;

11、 void sort(); friend ostream iarray.getSize (); i+) os arrayi ; return os; private: int * data; unsigned int size; ; void readFromFile ( const char *, IntArray void writeToFile (char*, const IntArray /main.h #include fstream #include “IntArray. h“ void IntArray:sort () /* 333* /* 666* void readFromF

12、ile (const char * f, IntArray if (infile.fail () cerr “打开输入文件失败!“; return; int i=0; while (!infile.eof() infile mi+; int main () IntArray a1(3), a2(7), a3(1000);a10=3, a11=1, a12=2; a20=5, a21=2, a22=7, a23=4, a24=1, a25=6, a26=3; readFromFile (“in.dat“, a3); cout “-排序前-/n“; cout “a1=“ a1 endl; cout

13、 “a2=“ a2 endlendl; al.sort (); a2.sort(); a3.sort(); cout “-排序后- /n“; cout “a1=“ a1endl; cout “a2=“ a2endlendl; writeToFile(“, a3); return 0; (分数:40.00)_二级 C+-73 (1)答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1,其中包含类 Myaass的定义。程序中位于每个“/ERROR *found*”下的一

14、行语句有错误,请加以更正。更正后程序的输出结果应该是: The value is 5 The value is 10 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class MyClass public: / ERROR * found* voidMyClass() value = 0; / ERROR * found* void setValue(int val) const value=val; int getValue() const return value; pr

15、ivate: /ERROR *found* int value=0; ; int main() MyClass obj; obj.setValue(5); cout “The value is“ obj. getValue() endl; obj.setValue(10); cout “The value is“ obj. getValue() endl; return 0; (分数:30.00)_正确答案:(1)MyClass()value=0; (2)void setValue(int val) (3)int value;)解析:考点 本题考查的是:MyClass 类,其中涉及构造函数、成

16、员函数和 const函数。 解析 (1)主要考查考生对构造函数的掌握,构造函数前不能添加任何返回类型。 (2)主要考查考生对 const的掌握,由函数中 value=val;语句,可知成员的值发生改变,因此不能用 const。 (3)主要考查考生对私有成员的掌握,私有成员只能声明,不能赋初始值。二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2,其中定义了 vehicle类,并派生出 motorcar类和 bicycle类。然后以 motorcar和 bicycle作为基类,再派生出 motocycle类。要求将v

17、ehicle作为虚基类,避免二义性问题。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: A vehicle is running! A vehicle has stopped! A bicycle is running! A bicycle has stopped! A motorcar is running! A motocycle is running! 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream.h class vehicle private: int MaxSpe

18、ed; int Weight; public: vehicle(): MaxSpeed(0), Weight(0) vehicle(int max_speed, int weight): MaxSpeed (max_speed ), Weight (weight)( /* found* _Run() cout “Avehicle is running!“ endl; /* found* _Stop() cout “A vehicle has stopped!“ endl; ; class bicycle : virtual public vehicle private: int Height;

19、 public: bicycle(): Height(0) bicycle(int max_speed, int weight,int height) :vehicle (max_speed, weight), Height(height); void Run () cout “A bicycle isrunning!“ endl; void Stop() cout “Abicycle hasstopped!“ endl; ; class motorcar : virtual public vehicle private: int SeatNum; public: motorcar(): Se

20、atNum(0) motorcar (int max_speed, intweight, int seat_num) /* found* :_ void Run() cout “A motorcar isrunning!“ endl; void Stop () cout “A motorcarhas stopped!“ endl; ; /* found* class motorcycle: _ public: motorcycle() motorcycle (int max_speed, int weight, int height, int seet_num):bicycle(max_spe

21、ed, weight, height), motorcar (max_speed, weight, seet_num); motorcycle () ; void Run () cout “A motorcycle is running!“ endl; void Stop() cout “A motorcycle has stopped!“ endl; ; int main() vehicle * ptr; vehicle a; bicycle b; motorcar c; motorcycle d; a.Run(); a. Stop(); b.Run(); b. Stop(); ptr =

22、ptr-Run(); ptr = ptr-Run(); return 0; (分数:30.00)_正确答案:(1)virtual void (2)virtual void (3)vehicle(max_speed,weight),SeatNum(seat_num) (4)public bicycle,public motorcar)解析:考点 本题考查 vehicle类及其派生类 bicycle、和 motorcar类和 motorcyrcle类,其中涉及虚函数、虚基类、构造函数和成员函数。 解析 (1)和(2)主要考查考生对虚函数的掌握,虚函数使用virtual定义。 (3)主要考查考生对构

23、造函数的掌握,使用成员列表初始化。 (4)主要考查考生对派生类的掌握,派生类继承基类时要表明继承方式,公有继承为 public,多个继承时要使用“,”隔开。三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜单打开考生文件夹 proj3下的工程 proj3,其中定义的 IntArray是一个用于表示整型一维数组的类。成员函数 swap可以将数组中的两个指定元素交换位置;成员函数 sort的功能是将数组元素按照升序排序。请编写成员函数 sort。在 main函数中给出了一组测试数据,此时程序运行中应显示: 读取输入文件 -排序前- a1=3 1 2 a2=5 2 7

24、 4 1 6 3 -排序后- a1=1 2 3 a2=1 2 3 4 5 6 7 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat中。输出函数 WriteToFile已经编译为 obj文件,并且在本程序中调用。 /IntArray.h #include iostream #include string.h using namespace std; class IntArray public: IntArray(unsigned int n) size = n; data = new intsize; In

25、tArray() delete data; int getSize() const return size; int void swap(int i, int j) int temp = datai; datai = dataj; dataj = temp; void sort(); friend ostream iarray.getSize (); i+) os arrayi ; return os; private: int * data; unsigned int size; ; void readFromFile ( const char *, IntArray void writeT

26、oFile (char*, const IntArray /main.h #include fstream #include “IntArray. h“ void IntArray:sort () /* 333* /* 666* void readFromFile (const char * f, IntArray if (infile.fail () cerr “打开输入文件失败!“; return; int i=0; while (!infile.eof() infile mi+; int main () IntArray a1(3), a2(7), a3(1000);a10=3, a11

27、1, a12=2; a20=5, a21=2, a22=7, a23=4, a24=1, a25=6, a26=3; readFromFile (“in.dat“, a3); cout “-排序前-/n“; cout “a1=“ a1 endl; cout “a2=“ a2 endlendl; al.sort (); a2.sort(); a3.sort(); cout “-排序后- /n“; cout “a1=“ a1endl; cout “a2=“ a2endlendl; writeToFile(“, a3); return 0; (分数:40.00)_正确答案:(for(int i=0; isize; i+) /i 从 0到 size-1遍历 for(int j=i+1; jsize; j+) /j从(i+1)到(size-1)遍历 if(dataidataj) /如果 dataidataj swap(i, j); /i 与 j交换位子)解析:考点 本题考查的是 IntArray类,其中涉及动态数组、构造函数、析构函数和成员函数。 解析 主要考查考生对排序算法的掌握,sort 函数的功能是将数组元素按照从小到大的顺序排序。使用 for循环遍历数组元素,变量 i和 j代表数组元素下标,将数组元素 i和 j进行比较,顺序不对就调用 swap函数交换元素。

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