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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

【计算机类职业资格】C++语言笔试-8及答案解析.doc

1、C+语言笔试-8 及答案解析(总分:100.00,做题时间:90 分钟)一、操作题(总题数:3,分数:100.00)1.请使用 VC6 或使用答题菜单打开考生文件夹 proj1 下的工程 projl。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:Name:Smith Age:21 ID:99999 CourseNum: 12Record:970注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。#include iostreamusing namespace std;class Studentlnfo

2、protected:/ERROR *found*char Name;int Age;int ID;int CourseNum;float Record;public:Studentlnfo(char*name,int Age,int ID,int courseNum,float record);/ERROR *found*void Studentlnfo()float AverageRecord()return Record/CourseNum;void show()constcout“Name:“Name“Age:“CourseNum:“CourseNum“Record:“Recordend

3、l;/ERROR *found*Studentlnfo Studentlnfo (char*Name,int Age,int ID,int CourseNum,float Record)Name=name;Age=age;this-ID=ID;CourseNum=courseNum;Record=record;int main()Studentlnfo st(“Smith“,21,99999,12,970);st.show();return 0;(分数:30.00)_2.请使用 VC6 或使用答题菜单打开考生文件夹 proj2 下的工程 proj2,其中定义了 vehicle 类,并派生出 m

4、otorcar 类和 bicycle 类。然后以 motorcar 和 bicycle 作为基类,再派生出 motorcycle 类。要求将vehicle 作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:801501001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/ *found*”。#include iostream.hclass vehicleprivate:int MaxSpeed;int Weight;public:/*found*vehicle (int maxspeed,intw

5、eight):_vehicle();int getMaxSpeed()return MaxSpeed;int getWeight()return Weight;/*found*class bicycle:_public vehicleprivate:int Height;public:bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height)int getHeight()return Height;/*found*class motorcar:_public vehicleprivate

6、int SeatNum;public:motorcar(int maxspeed,int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum)int getSeatNum()return SeatNum;/*found*class motorcycle:_public:motorcycle(int maxspeed,intweight,int height):vehicle (maxspeed,weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,

7、1);void main ()motorcycle a(80,150,100);couta.getMaxSpeed()endl;couta.getWeight()endl;couta.getHeight()endl;couta.getSeatNum()endl;(分数:30.00)_3.请使用 VC6 或使用答题菜单打开考生文件夹 proj3 下的工程 proj3,其中声明的 CDeepCopy 是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数 operator=,以实现深层复制。要求:补充编制的内容写在“/*333*”与“/*666*”之间。不得修改程序的其他部分。注意:程序最后将结

8、果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/CDeepCopy.h#includeiostream#includestringusing namespace std;class CDeepCopypublic:int n; /动态数组的元素个数int*p; /动态数组首地址CDeepCopy(int);CDeepCopy();CDeepCopy/赋值运算符函数;void writeToFile (char*);/main.cpp#include“CDeepCopy.h“CDeepCopy:CDeepCopy()delete

9、p;CDeepCopy:CDeepCopy(int k)n=k;p=new intn;)/构造函数实现CDeepCopya.p0=1;d.p0=666;/对象 a,d 数组元素的赋值CDeepCopy b(3);a.p0=88;b=a;/调用赋值运算符函数coutb.p0;/显示内层局部对象的数组元素coutd.p0;/显示 d 数组元素 a.p0的值cout“d fade away;/n“;couta.p0;/显示 a 数组元素 a.p0的值writeToFile(“ “);return 0;(分数:40.00)_C+语言笔试-8 答案解析(总分:100.00,做题时间:90 分钟)一、操作

10、题(总题数:3,分数:100.00)1.请使用 VC6 或使用答题菜单打开考生文件夹 proj1 下的工程 projl。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为:Name:Smith Age:21 ID:99999 CourseNum: 12Record:970注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。#include iostreamusing namespace std;class Studentlnfoprotected:/ERROR *found*char Name;int Ag

11、e;int ID;int CourseNum;float Record;public:Studentlnfo(char*name,int Age,int ID,int courseNum,float record);/ERROR *found*void Studentlnfo()float AverageRecord()return Record/CourseNum;void show()constcout“Name:“Name“Age:“CourseNum:“CourseNum“Record:“Recordendl;/ERROR *found*Studentlnfo Studentlnfo

12、char*Name,int Age,int ID,int CourseNum,float Record)Name=name;Age=age;this-ID=ID;CourseNum=courseNum;Record=record;int main()Studentlnfo st(“Smith“,21,99999,12,970);st.show();return 0;(分数:30.00)_正确答案:(1)char*Name;(2)Studentlnfo()(3)Studentlnfo:Studentlnfo(char*name,int age,intID,int courseNum,float

13、 record)解析:解析 本题考查 Studentlnfo 类,其中涉及构造函数、动态数组、析构函数和成员函数。声明数组时要指定数组的大小,否则将会导致程序出错,不论是构造函数还是析构函数都不能在函数名前添加返回类型。(1)主要考查考生对动态数组的掌握,由题目可知 Name 应该指向一个动态数组,而不是一个有效 char 型字符,因此要定义成 char 型指针。(2)主要考查考生对析构函数的掌握,析构函数不需要函数返回类型,应把 void 去掉。(3)主要考查考生对构造函数定义的掌握,构造函数也要使用作用域符号“:”。2.请使用 VC6 或使用答题菜单打开考生文件夹 proj2 下的工程 p

14、roj2,其中定义了 vehicle 类,并派生出 motorcar 类和 bicycle 类。然后以 motorcar 和 bicycle 作为基类,再派生出 motorcycle 类。要求将vehicle 作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:801501001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/ *found*”。#include iostream.hclass vehicleprivate:int MaxSpeed;int Weight;public:/*found

15、vehicle (int maxspeed,intweight):_vehicle();int getMaxSpeed()return MaxSpeed;int getWeight()return Weight;/*found*class bicycle:_public vehicleprivate:int Height;public:bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height)int getHeight()return Height;/*found*class moto

16、rcar:_public vehicleprivate:int SeatNum;public:motorcar(int maxspeed,int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum)int getSeatNum()return SeatNum;/*found*class motorcycle:_public:motorcycle(int maxspeed,intweight,int height):vehicle (maxspeed,weight),bicycle(maxspeed,weight,height

17、),motorcar(maxspeed,weight,1);void main ()motorcycle a(80,150,100);couta.getMaxSpeed()endl;couta.getWeight()endl;couta.getHeight()endl;couta.getSeatNum()endl;(分数:30.00)_正确答案:(1)MaxSpeed(maxspeed),Weight(weight);(2)virtual(3)virtual(4)public bicycle,public motorcar)解析:解析 本题考查 vehicle 类及其派生类 motorcar

18、和 bicycle,再由这两类派生出 motorcycle 类,其中涉及构造函数、成员函数和析构函数。构造函数采用成员初始化列表来完成对私有成员的初始化,派生类的书写要注意关键字。(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员 MaxSpeed 和 Weight 初始化。(2)主要考查考生对派生类的掌握,题目要求将 vehicle 作为虚基类,避免二义性问题。因此在这里添加virtual 使 vehicle 成为虚基类。(3)主要考查考生对派生类的掌握,题目要求以 motorcar 和 bicycle 作为基类,再派生出 motorcycle 类。在主函数中可以看到 m

19、otorcycle 类的实例 a 调用 getHeight 函数和 getSeat-Num 函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。虚基类继承时要添加关键字 virtual,以避免二义性。3.请使用 VC6 或使用答题菜单打开考生文件夹 proj3 下的工程 proj3,其中声明的 CDeepCopy 是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数 operator=,以实现深层复制。要求:补充编制的内容写在“/*333*”与“/*666*”之间。不得修改程序的其他部分。注意:程序最后将结果输出到文件 out.

20、dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/CDeepCopy.h#includeiostream#includestringusing namespace std;class CDeepCopypublic:int n; /动态数组的元素个数int*p; /动态数组首地址CDeepCopy(int);CDeepCopy();CDeepCopy/赋值运算符函数;void writeToFile (char*);/main.cpp#include“CDeepCopy.h“CDeepCopy:CDeepCopy()deletep;CDeepCopy

21、CDeepCopy(int k)n=k;p=new intn;)/构造函数实现CDeepCopya.p0=1;d.p0=666;/对象 a,d 数组元素的赋值CDeepCopy b(3);a.p0=88;b=a;/调用赋值运算符函数coutb.p0;/显示内层局部对象的数组元素coutd.p0;/显示 d 数组元素 a.p0的值cout“d fade away;/n“;couta.p0;/显示 a 数组元素 a.p0的值writeToFile(“ “);return 0;(分数:40.00)_正确答案:(n=r.n; /把对象 r 字符长度赋值给 ndeletep; /删除动态数组 pp=new intn;/给动态数组 p 分配空间为 nfor(int i=0;in;i+)/遍历对象 r 中的数组 ppi=r.pi;/把 r.i赋值给 pireturn*this; /返回被赋值的对象)解析:解析 本题考查 CDeepCopy 类,其中涉及动态数组、构造函数、析构函数和运算符重载。运算符重载要先把类的定义弄清,其次要理解被重载的运算符的含义。主要考查考生对运算符重载的掌握,由注释可知此处要实现赋值运算符函数。要重载的运算符是“=”,该类的成员是动态数组 p,数组元素个数为 n,因此先释放原来的动态数组,再分配空间,然后逐个复制元素即可。

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