[计算机类试卷]国家二级C++机试(操作题)模拟试卷505及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷505及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷505及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 505及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,此工程中含有一个源程序文件proj1 cpp。其中位于每个注释 “ ERROR*found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called The value is10 Max number is20 Destructor called 注意:只能修改注释 “ ERROR*found*”的下一行语句,不 要改动程序中的其他内容。 proj1 cpp #include iostream using namespace s
2、td; class MyClasS public: ERROR*found* void MyClass(int i) value=i; cout “Constructor called “ endl; int Max(int x, int y)return x y?x: y; 求两个整数的最大值 ERROR*found* int Max(int x, int y, int z=0) 求三个整数的最大值 if(x y) return x z?x: z; elSe return y z?y: z; int GetValue( )constreturnvalue; MyClass( )cout “D
3、estructor called “ endl; private: int value; ; int main( ) MyClass obj(10); ERROR*found* cout “The value is“ value( ) endl; cout “Max number is“ obj Max(10, 20) endl; return0; 二、简单应用题 2 请打开考生文件夹下的解决方案文件 pmj2,其中在编辑窗口内显示的主程序文件中定义有类 XBase和 XDerived,以及主函数 main。程序文本中位于每行 “*found*下面的一行内有一处或多处下划线标记,请在每个下划线
4、标记处填写合适的内容,并 删除掉下划线标记。经修改后运行程序,得到的输出结果为: s=25 #include iostream using namespace std: class XBase private: int mem1, mem2; public: *found* XBase(int m1=0, int m2=0): mem1(m1), _ *found* virtual int_ ; *found* class XDerivred: _ private: int mem3; public: XDerired( ): XBase( ), mem3(0) *found* XDerire
5、d(int m1, int m2, int m3): _ int sum( )return XBase: sum( )+mere3; ; void main( ) XDerived b(3, 4, 5); XBase a(6, 7), *pb=&b; int s=pb- sum( )+a sum( ); cout “s=“ s endl; 三、综合应用题 3 请打开考生文件夹下的解决方案文件 proj3,其中包含了类 Integers和主函数main的定义。一个 Integers对象就是一个整数的集合,其中包含 0个或多个可重复的整数。成员函数 add的作用是将一个元素添加到集合中,成员函数
6、remove的作用是从集合中删除指定的元素 (如果集合中存在该元素 ),成员函数 sort的作用是将集合中的整数按升序进行排序。请编写这个 sort函数。此程序的正确输出结果应为: 5 28 2 4 5 3 2 75 27 66 31 5 28 2 4 5 3 2 75 27 66 31 6 5 28 2 4 5 3 2 75 27 66 31 6 19 5 28 4 5 3 2 75 27 66 31 6 19 5 28 4 5 3 2 75 27 66 31 6 19 4 2 3 4 4 5 5 6 19 27 28 31 66 75 要求: 补充编制的内容写在 “ *333*”与 “ *
7、666*”之间。不得修改程序的其他部分。 注意:相关文件包括 : main cpp、 Integers h。 程序最后调用 writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件 out dat中。输出函数 writeToFile已经编译为 obj文件。 Integers h #ifndef INTEGERS #define INTEGERS #include iostream using namespace std; const int MAXELEMENTS=100; 集合最多可拥有的元素个数 class Integers int elemMAXELEMENTS;
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 505 答案 解析 DOC
