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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

[计算机类试卷]国家二级C++机试(操作题)模拟试卷287及答案与解析.doc

1、国家二级 C+机试(操作题)模拟试卷 287及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,此工程中含有一个源程序文件 proj1 cpp。其中位于每个注释 “ ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called The value is 10 Copy constructor called The value is 10 Destructor called Destructor called 注意:只修改注释 “ ERROR *found*”的下一行语

2、句,不要改动程序中的其他内容。 proj1 cpp #include iostream using namespace std; class MyClass public: ERROR *found* MyClass(int i) value i; cout “Constructor called “ end1; ERROR *found* MyClass(const MyClass P) value P value; cout “Copy constructor called “ end1; void Print() cout “The value is“ value end1; ) ERR

3、OR *found* void MyClass() cout “Destructor called “ end1; private: int value; , int main() MyClass obj1; obj 1 Print(); MyClasS obj2(obj1); obj 2 Print(); return 0; 二、简单应用题 2 请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工程 proj2,其中有矩阵基类 MatrixBase、矩阵类 Matrix和单位阵 UnitMatrix的定 义,还有 main函数的定义。请在横线处填写适当的代码并删除横线,以实现上述

4、类定义。此程序的正确输出结果应为: 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 #include iostream using namespace std; 矩阵基础类,一个抽象类 class MatrixBase int rows r cols; public: MatrixBase(int rows, int cols): rows

5、(rows), cols(cols) int getRows()constreturn rows; 矩阵行数 int getCols()constreturn cols; 矩阵列数 virtual double getElement(int r, int c)const 0;取第 i个元素的值 void show()const 分行显示矩阵中所有元素 for(int i 0; i rows; i ) cout end1; for(int j 0; j cols; j ) *found* cout _ “; ; 矩阵类 class Matrix: public Matrix- Base doub

6、le *val; public: *found* Matrix(int rows, int cols, double m NULL): _ *found* val _; for(int i 0; i rows *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 MatrixBase( public: U

7、nitMatrix(int rows): MatrixBase(rows, rows) 单位阵行数列数相同 double getElement(int r, int c)const *found* if(_)return 1 0; return 0 0; ; int main()f 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; cout end1; m new UnitMatrix(6); m sh

8、ow(); delete m; return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中声明的 DataList类,是一个用于表示数据表的类。 DataList的重载运算符函数operator,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个 operator函数。程序的正确输出应该是: 两个数据表: 1, 2, 3, 4, 5, 6 3, 4, 5, 6, 7, 8 两个数据表之和: 4, 6, 8, 10, 12, 14 要求: 补充编制的内容写在

9、“ *333*”与 “ *666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out dat中。输出函数 writeToFile已经编译为 obj文件,并且在本程序中调用。 DataList h #include iostream using namespace std; class DataList数据表类 int len; double *d; public: DataList(int len, double data NULL); DataList(DataList&data); int length()constreturnlen; double getEleme

10、nt(int i) constreturn di; ) DataList operator (const DataList&list)const;两个数据表求和 void show()const;显示数据表 ; void writeToFile(char *, const DataList&); main cpp #include“DataList h“ DataList DataList(int len, double data): len(1en) d new doublelen; for(int i 0; i len; i ) di (data NULL?0 0: datai); Dat

11、aList DataList(DataList &data): fen(data fen) d new doublelen; for(int i 0; i len; i ) di data di; DataList DataList operator (const DataList&list)const 两个数据表求和 double * dd new double list 1ength(); *333* *666* return DataList(list length(), dd); void DataList show()const显示数据表 for(int i 0; i len 1;

12、i ) cout di “, “; cout dlen 1 end1; int main() double sl (1, 2, 3, 4, 5, 6; double s2 3, 4, 5, 6, 7, 8); DataList listl(6, s1), list2 (6, s2);定义两个数据表对象 cout “两个数据表: “ end1; list1 show(); list2 show(); cout end1 “两个数据表之和: “ end1; (list1 list2) show(); writeToFile ( “, listl list2); return 0; 国家二级 C+机

13、试(操作题)模拟试卷 287答案与解析 一、基本操作题 1 【正确答案】 (1)MyClass(int i 10) (2)MyClass(const MyClass & p) (3) MyClass() 【试题解析】 (1)考查构造函数参数默认值,题目要求输出语句: The value is 10,从主函数中可以看出, obj1并没有初始化,但是 obj1调用 Print()函数时它的值为 10,由此可知构造函数的形参有默认值,且值为 10,因此得出语句MyClass(int i 10)。 (2)主要考查考生对复制构造函数的掌握,复制构造函数的形参都为引用,同时为了不改变形参的值要加上 con

14、st,因此得出语句 MyClass(const MyClass & p)。 (3)主要考查考生对析构函数的 掌握,析构函数和构造函数一样,前面不能添加任何类型,要把 void去掉。 二、简单应用题 2 【正确答案】 (1)getElement(i, j) (2)MatrixBase(rows, cols) (3)new doublerows*cols (4)r c 【试题解析】 (1)主要考查考生对纯虚函数的掌握,函数功能是分行显示矩阵中所有元素。因此在这里要输出行为 i、列为 j的元素,使用纯虚函数getElement(i, j)实现,输出语句为 cout getElement(i, j) “ “;。 (2)主要考查考生对派生类的构造函数的掌握,派生类的构造函数使用成员列表初始化法,先对基类初始化。 (3)主要考查考生对动态数组的掌握, val是 double型指针,要给 val赋值,就要先给它分配空间,应使用 new来完成。 (4)主要考查考生对成员函数的掌握,因为要输出单位矩阵,只有满足条件 rc的元素为 1 0,所以填写语句 if(r c)return 1 0;。 三、综合应用题 3 【正确答案】 for(int i 0; i len; i) 遍历对象 list中的数组和 d数组,把对应的值相加后放到数组 dd中。 ddi di list di;

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