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