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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

【计算机类职业资格】二级C++分类模拟125及答案解析.doc

1、二级 C+分类模拟 125 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1。程序中位于每个“/ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只修改每个“/ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class S

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

3、Age “ID:“ ID “CourseNum:“ CourseNum “Record:“ Record endl; ; / ERROR *found* StudentInfo StudentInfo (char * Name, int Age, int ID, int CourseNum, float Record) Name = name; Age = age; this - ID = ID; CourseNum = courseNum; Record = record; int main() StudentInfo st (“Smith“,21,99999,12,970); st.sho

4、w(); return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,其中定义了 vehicle 类,并派生出motorcar 类和 bicycle 类。然后以 motorcar 和 bicycle 作为基类,再派生出 motorcycle 类。要求将vehicle 作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 80 150 100 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/

5、found*”。 #include iostream.h class vehicle private: int MaxSpeed; int Weight; public: / *found* vehicle (int maxspeed, int weight):_ vehicle() ; int getMaxSpeed() return MaxSpeed; int getWeight() return Weight; ; / *found* class bicycle:_ public vehicle private: int Height; public: bicycle (int max

6、speed, int weight, int height): vehicle (maxspeed, weight), Height (height) int getHeight () return Height; ; / *found* class motorcar:_ public vehicle private: int SeatNum; public: motorcar (int maxspeed, int weight, int seatnum):vehicle (maxspeed, weight), SeatNum (seatnum) int getSeatNum() return

7、 SeatNum; ; / *found* class motorcycle:_ public: motorcycle(int maxspeed, int weight, int height): vehicle (maxspeed, weight), bicycle (maxspeed, weight, height), motorcar (maxspeed, weight, 1) ; void main() motorcycle a(80,150,100); cout a.getMaxSpeed() endl; cout a.getWeight() endl; cout a.getHeig

8、ht() endl; cout a.getSeatNum() endl; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程 proj3,其中声明的 CDeepCopy 是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数 operator=,以实现深层复制。 要求: 补充编制的内容写在“/ *333*”与“/ *666*”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。 /CDeepCopy.

9、h #include iostream #include string using namespace std; class CDeepCopy public: int n; /动态数组的元素个数 int *p; /动态数组首地址 CDeepCopy(int); CDeepCopy(); CDeepCopy /赋值运算符函数 ; void writeToFile(char *); /main.cpp #include “CDeepCopy.h“ CDeepCopy:CDeepCopy() delete p; CDeepCopy:CDeepCopy(int k) n=k; p=new intn;

10、 /构造函数实现 CDeepCopy a.p0 = 1; d.p0 = 666; /对象 a,d 数组元算的赋值 CDeepCopy b(3); a.p0 = 88; b = a; /调用赋值运算符函数 cout b.p0; /显示内层局部对象的数组元素 cout d.p0; /显示 d 数组元算 a.p0的值 cout “d fade away; /n“; cout a.p0; /显示 a 数组元素 a.p0的值 writeToFile(“ “); return 0; (分数:40.00)_二级 C+分类模拟 125 答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数

11、1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1。程序中位于每个“/ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只修改每个“/ ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class StudentInfo protected: / ERROR *found* char Name; int

12、 Age; int ID; int CourseNum; float Record; public: StudentInfo(char * name, int Age, int ID, int courseNum, float record); / ERROR *found* void StudentInfo() float AverageRecord() return Record/CourseNum; void show() const cout “Name:“ Name “Age:“ Age “ID:“ ID “CourseNum:“ CourseNum “Record:“ Record

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

14、)StudentInfo() (3)StudentInfo:StudentInfo (char*name,int age,int ID,int courseNum,float record) 答案考生文件夹 考点 本题考查 StudentInfo 类,其中涉及构造函数、动态数组、析构函数和成员函数。声明数组时要指定数组的大小,否则将会导致程序出错,不论是构造函数还是析构函数都不能在函数名前添加返回类型。 解析 (1)主要考查考生对动态数组的掌握,由题目可知 Name 应该指向一个动态数组,而不是一个有效char 型字符,因此要定义成 char 型指针。 (2)主要考查考生对析构函数的掌握,析构

15、函数不需要函数返回类型,应把 void 去掉。 (3)主要考查考生对构造函数定义的掌握,构造函数也要使用作用域符号“:”。二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,其中定义了 vehicle 类,并派生出motorcar 类和 bicycle 类。然后以 motorcar 和 bicycle 作为基类,再派生出 motorcycle 类。要求将vehicle 作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 80 150 100 1 注意:只能在

16、横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/ *found*”。 #include iostream.h class vehicle private: int MaxSpeed; int Weight; public: / *found* vehicle (int maxspeed, int weight):_ vehicle() ; int getMaxSpeed() return MaxSpeed; int getWeight() return Weight; ; / *found* class bicycle:_ public vehicle private: i

17、nt 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: motorcar (int maxspeed, int weight, int seatnum):vehicle (maxspeed, weight), SeatNu

18、m (seatnum) int getSeatNum() return SeatNum; ; / *found* class motorcycle:_ public: motorcycle(int maxspeed, int weight, int height): vehicle (maxspeed, weight), bicycle (maxspeed, weight, height), motorcar (maxspeed, weight, 1) ; void main() motorcycle a(80,150,100); cout a.getMaxSpeed() endl; cout

19、 a.getWeight() endl; cout a.getHeight() endl; cout a.getSeatNum() endl; (分数:30.00)_正确答案:()解析:(1)MaxSpeed(maxspeed),Weight(weight); (2)virtual (3)virtual (4)public bicycle,public motorcar 答案考生文件夹 考点 本题考查 vehicle 类及其派生类 motorcar 和 bicycle,再由这两类派生出motorcycle 类,其中涉及构造函数、成员函数和析构函数。构造函数采用成员初始化列表来完成对私有成员的初

20、始化,派生类的书写要注意关键字。 解析 (1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员 MaxSpeed 和 Weight初始化。 (2)主要考查考生对派生类的掌握,题目要求将 vehicle 作为虚基类,避免二义性问题。因此在这里添加virtual 使 vehicle 成为虚基类。 (3)主要考查考生对派生类的掌握,题目要求以 motorcar 和 bicycle 作为基类,再派生出 motorcycle 类。在主函数中可以看到 motorcycle 类的实例 a 调用 getHeight 函数和 getSeatNum 函数,由此可知这两个基类都是公有继承,因此得出语

21、句:public bicycle,public motorcar。 虚基类继承时要添加关键字 virtual,以避免二义性。三、综合应用题(总题数:1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程 proj3,其中声明的 CDeepCopy 是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数 operator=,以实现深层复制。 要求: 补充编制的内容写在“/ *333*”与“/ *666*”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调

22、用。 /CDeepCopy.h #include iostream #include string using namespace std; class CDeepCopy public: int n; /动态数组的元素个数 int *p; /动态数组首地址 CDeepCopy(int); CDeepCopy(); CDeepCopy /赋值运算符函数 ; void writeToFile(char *); /main.cpp #include “CDeepCopy.h“ CDeepCopy:CDeepCopy() delete p; CDeepCopy:CDeepCopy(int k) n=

23、k; p=new intn; /构造函数实现 CDeepCopy a.p0 = 1; d.p0 = 666; /对象 a,d 数组元算的赋值 CDeepCopy b(3); a.p0 = 88; b = a; /调用赋值运算符函数 cout b.p0; /显示内层局部对象的数组元素 cout d.p0; /显示 d 数组元算 a.p0的值 cout “d fade away; /n“; cout a.p0; /显示 a 数组元素 a.p0的值 writeToFile(“ “); return 0; (分数:40.00)_正确答案:()解析:n = r.n; /把对象 r 字符长度赋值给 n d

24、elete p; /删除动态数组 p p = new intn; /给动态数组 p 分配空间为 n for (int i = 0; i n; i+) /遍历对象 r 中的数组 p pi = r.pi; /把 r.pi赋值给 pi return * this; /返回被赋值的对象 答案考生文件夹 考点 本题考查 CDeepCopy 类,其中涉及动态数组、构造函数、析构函数和运算符重载。运算符重载要先把类的定义弄清,其次要理解被重载的运算符的含义。 解析 主要考查考生对运算符重载的掌握,由注释可知此处要实现赋值运算符函数。要重载的运算符是“=”,该类的成员是动态数组 p,数组元素个数为 n,因此先释放原来的动态数组,再分配空间,然后逐个复制元素即可。

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