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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

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

1、C+语言笔试-10 及答案解析(总分:100.00,做题时间:90 分钟)一、操作题(总题数:3,分数:100.00)1.请使用 VC6 或使用答题菜单打开考生文件夹 proj1 下的工程 proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“/ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:Constructor called.The value is 10Copy constructor called.The value is 10Destructor called.Destructor called.注意:只修改注释“/ERR

2、OR *found*”的下一行语句,不要改动程序中的其他内容。/proj1.cpp#include iostreamusing namespace std;class MyClass public:/ERROR *found*MyClass(int i)value=i;cout“Construc-tor called.“endl;/ERROR *found*MyClass(const MyClass p)value=p.value;cout“Copy constructorcalled.“endl;void Print ()cout“The value is“valueendl;/ERROR

3、found*void MyClass()cout“Destructor called.“endl;private:int value;int main()MyClass obj1;obj1.Print();MyClass obj2(obj1);obj2.Print();return 0;(分数:30.00)_2.请使用 VC6 或使用答题菜单打开考生文件夹 proj2 下的工程 proj2,其中有矩阵基类 MatrixBase、矩阵类 Matnx 和单位阵 UnitMatrix 的定义,还有 mam 函数的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:

4、1 2 3 4 52 3 4 5 63 4 5 6 71 0 0 0 0 00 1 0 0 0 00 0 1 0 0 00 0 0 1 0 00 0 0 0 1 00 0 0 0 0 1注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。#includeiostreamusing namespace std;/矩阵基础类,一个抽象类class MatrixBaseint rows,cols;public:MatrixBase(int rows,int cols):rows(rows),cols(cols)int getRows()constretu

5、rn rows;/矩阵行数int gatCols()constreturn cols;/矩阵列数virtual double getElement(int r,int c)const=0;/取第 i 个元素的值void show() const/分行显示矩阵中所有元素for(int i=0;irows;i+)coutendl;for(int j=0;jcols;j+)/*found*COUt_“ “;/矩阵类class Matrix:public MatrixBasedouble*val;public:/*found*Matrix(int rows,int cols,double m=NuLL

6、):_/*found*val=_;for(int i=0;irows* cols;i+)vali=(m=NuLL?0.0:mi);Matrix()deleteval;double getElement(int r,int c)constreturn valr* getCols()+c;/单位阵(主对角线元素都是 1,其余元素都是 0 的方阵)类class UnitMatrix: public MatrixBasepublic:UnitMatrix(int rows):MatrixBase(rows,rows)/单位阵行数列数相同double getElement(int r,int c)con

7、st/*found*if(_)return 1.0;return 0.0;int main()MatrixBase*m;double d5=1,2,3,4,5,2,3,4,5,6,3,4,5,6,7;m=new Matrix(3,5,(double*)d);m-show();delete m;coutendl;m=new UnitMatrix(6);m-show();delete m;return 0;(分数:30.00)_3.请使用 VC6 或使用答题菜单打开考生文件夹 proj3 下的工程 proj3,其中声明的 DataList 类,是一个用于表示数据表的类。DataList 的重载运算

8、符函数 operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确输出应该是:两个数据表:1,2,3,4,5,63,4,5,6,7,8两个数据表之和:4,6,8,10,12,14要求:补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/DataList.h#include iostreamusing namespac

9、e std;class Datalist /数据表类int len;double*d;public:DataList(int len,double data=DataList(Datalist int length () constreturn len;double getElement(int i)const return di;Datalist operator+(const DataList /两个数据表求和void show () const; /显示数据表 void writeToFile(char*,constDataList/main.cpp#include“Datalist.h

10、DataList:DataList(int len,doubledata):len(len)d=new doublelen;for(int i=0;ilen;i+)di=(data=NULL?0.0:datai);DataList:Datalist(Datalist for(int i=0;ilen;i+)di=data.di;DataList DataList:operator+(constDatalist/*333*/*666*return DataList(list.length(),dd);void DataList:show()const(/显示数据表for(int i=0;ile

11、n-1;i+)coutdi“,“;coutdlen-1endl;int main()double s1=1,2,3,4,5,6;double s2=3,4,5,6,7,8;DataList list1(6,s1),list2(6,s2); /定义两个数据表对象cout“两个数据表:“endl;list1.show();list2.show();coutendl“两个数据表之和:“endl;(list1+list2).show();writeToFile(“ “,list1+list2);return 0;(分数:40.00)_C+语言笔试-10 答案解析(总分:100.00,做题时间:90 分

12、钟)一、操作题(总题数:3,分数:100.00)1.请使用 VC6 或使用答题菜单打开考生文件夹 proj1 下的工程 proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“/ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:Constructor called.The value is 10Copy constructor called.The value is 10Destructor called.Destructor called.注意:只修改注释“/ERROR *found*”的下一行语句,不要改动程序中的其他内容。/pro

13、j1.cpp#include iostreamusing namespace std;class MyClass public:/ERROR *found*MyClass(int i)value=i;cout“Construc-tor called.“endl;/ERROR *found*MyClass(const MyClass p)value=p.value;cout“Copy constructorcalled.“endl;void Print ()cout“The value is“valueendl;/ERROR *found*void MyClass()cout“Destructo

14、r called.“endl;private:int value;int main()MyClass obj1;obj1.Print();MyClass obj2(obj1);obj2.Print();return 0;(分数:30.00)_正确答案:(1)MyClass(int i=10)(2)MyClass(const MyClass/矩阵基础类,一个抽象类class MatrixBaseint rows,cols;public:MatrixBase(int rows,int cols):rows(rows),cols(cols)int getRows()constreturn rows;

15、/矩阵行数int gatCols()constreturn cols;/矩阵列数virtual double getElement(int r,int c)const=0;/取第 i 个元素的值void show() const/分行显示矩阵中所有元素for(int i=0;irows;i+)coutendl;for(int j=0;jcols;j+)/*found*COUt_“ “;/矩阵类class Matrix:public MatrixBasedouble*val;public:/*found*Matrix(int rows,int cols,double m=NuLL):_/*fou

16、nd*val=_;for(int i=0;irows* cols;i+)vali=(m=NuLL?0.0:mi);Matrix()deleteval;double getElement(int r,int c)constreturn valr* getCols()+c;/单位阵(主对角线元素都是 1,其余元素都是 0 的方阵)类class UnitMatrix: public MatrixBasepublic:UnitMatrix(int rows):MatrixBase(rows,rows)/单位阵行数列数相同double getElement(int r,int c)const/*foun

17、d*if(_)return 1.0;return 0.0;int main()MatrixBase*m;double d5=1,2,3,4,5,2,3,4,5,6,3,4,5,6,7;m=new Matrix(3,5,(double*)d);m-show();delete m;coutendl;m=new UnitMatrix(6);m-show();delete m;return 0;(分数:30.00)_正确答案:(1)getElement(i,j)(2)MatrixBase(rows,cols)(3)new doublerows*cols(4)r=c)解析:解析 本题考查 MatrixB

18、ase 类及其派生类 Matrix 和 UnitMatrix,其中涉及构造函数、const 函数、纯虚函数、动态数组和析构函数。派生类的构造函数要涉及基类的初始化,因此必须使用成员初始化列表。动态数组要先使用 new 语句分配空间,再赋值。(1)主要考查考生对纯虚函数的掌握,函数功能是分行显示矩阵中所有元素。因此在这里要输出行为 i、列为 j 的元素,使用纯虚函数 getElement(i,j)实现,输出语句为 coutgetElement(i,j)“ “;。(2)主要考查考生对派生类的构造函数的掌握,派生类的构造函数使用成员列表初始化法,先对基类初始化。(3)主要考查考生对动态数组的掌握,v

19、al 是 double 型指针,要给 val 赋值,就要先给它分配空间,应使用 new 来完成。(4)主要考查考生对成员函数的掌握,因为要输出单位矩阵,只有满足条件 r=c 的元素为 1.0,所以填写语句 if(r=c)return 1.0;。3.请使用 VC6 或使用答题菜单打开考生文件夹 proj3 下的工程 proj3,其中声明的 DataList 类,是一个用于表示数据表的类。DataList 的重载运算符函数 operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确

20、输出应该是:两个数据表:1,2,3,4,5,63,4,5,6,7,8两个数据表之和:4,6,8,10,12,14要求:补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的其他部分。注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中调用。/DataList.h#include iostreamusing namespace std;class Datalist /数据表类int len;double*d;public:DataList(int len,double data=DataList(Data

21、list int length () constreturn len;double getElement(int i)const return di;Datalist operator+(const DataList /两个数据表求和void show () const; /显示数据表 void writeToFile(char*,constDataList/main.cpp#include“Datalist.h“DataList:DataList(int len,doubledata):len(len)d=new doublelen;for(int i=0;ilen;i+)di=(data=

22、NULL?0.0:datai);DataList:Datalist(Datalist for(int i=0;ilen;i+)di=data.di;DataList DataList:operator+(constDatalist/*333*/*666*return DataList(list.length(),dd);void DataList:show()const(/显示数据表for(int i=0;ilen-1;i+)coutdi“,“;coutdlen-1endl;int main()double s1=1,2,3,4,5,6;double s2=3,4,5,6,7,8;DataLi

23、st list1(6,s1),list2(6,s2); /定义两个数据表对象cout“两个数据表:“endl;list1.show();list2.show();coutendl“两个数据表之和:“endl;(list1+list2).show();writeToFile(“ “,list1+list2);return 0;(分数:40.00)_正确答案:(for(int i=0;ilen;+i) /遍历对象 list 中的数组和 d 数组,把对应的值相加后放到数组dd 中。ddi=di+list.di;)解析:解析 本题考查 DataList 类,其中涉及构造函数、动态数组、复制构造函数、const 函数和运算符重载。主要考查考生对重载运算符的掌握,题目要求对两个数据表求和。程序已经定义了动态数组 dd,并已经分配好了空间,接下来只要运用循环语句完成元素相加并进行赋值即可。

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