[计算机类试卷]国家二级C++机试(操作题)模拟试卷487及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷487及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷487及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 487及答案与解析 一、基本操作题 1 请打开考生文件夹下的解决方案文件 proj1,此工程中含有一个源程序文件proj1 cpp。其中位于每个注释 “ ERROR*found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called The value is10 Copy constructor called The value is10 Destructor called Destructor called 注意:只修改注释 “ ERROR*found*”的下一行语句,不要改动程序中的其他内容。 proj1
2、cpp #include ioStream using namespace std; class MyClass public: ERROR*found* MyClass(int i) value=i; cout “Constructor called “ endl; ERROR*found* MyClasS(const MyClass P) value=p value; cout “Copy construc-tor called “ endl; void Print( ) cout “The value is“ value endl; ERROR*found* void MyClass(
3、) cout “DeStructorcalled “ endl; private: int value; ; int main( ) MyClass obj1; obj1 Print( ); MyClass obj2(obj1); obj2 Print( ); return0; 二、简单应用题 2 请打开考生文件夹下的解决方案文件 proj2,该工程中包含一个程序文件main cpp,其中有 “书 ”类 Book及其派生出的 “教材 ”类 TeachingMaterial的定义,还有主函数 main的定义。请在程序中 “ *found*”下的横线处填写适当的代码,然后删除横线,以实现上述类定义
4、和函数定义。此程序的正确输出结果应为: 教材名: C+语言程序设计 页数: 299 作者:张三 相关课程:面向对象的程序设计 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 #include iostream using namespace std; class Book “书 ”类 char*title;书名 int num pages;页数 char*writer;作者姓名 public: Book(const char*the_title, int pages, const char*the_writer): num pageS(pa
5、ges) title=new charstrlen(the_titie)+1; strcpy(title, the_title); *found* _ strcpy(writer, thewriter); *found* Book( ) _ int numOfPages( )constreturnnum_pages; )返回书的页数 const char*theTitle( )constreturn title; )返回书名 const char*theWriter( )constreturn writer; 返回作者名 ; class TeachingMaterial: publicBook
6、 “教材 ”类 char*course; public: TeachingMaterial(const char*the_title, int pages, const char*the_writer, const char*the_course) *found* : _ course=new charstrlen(the_course)+1; Strcpy(course, thecourse); TeachingMaterial( )delete course; const char*theCourse( )constreturn course; 返回相关课程的名称 ; int main(
7、) TeachingMaterial a_book(“C+语言程序设计 “, 299, “张三 “, ”面向对象的程序设计 ”); cout “教材名: “ a_book theTitle( ) endl “页数: “ a_book numOfPages( ) endl “作者: “ a_book theWriter( ) endl *found* “相关课程: “ _; cout endl; return0; 三、综合应用题 3 请打开考生文件夹下的解决方案文件 proj3,其中包含了类 IntegerSet和主函数main的定义。一个 IntegerSet对象就是一个整数的集合,其中包含
8、0个或多个无重复的整数;为了便于进行集合操作,这些整数按升序存放在成员数组 elem的前若干单元中。成员函数 add的作用是将一个元素添加到集合中 (如果集合中不存在该元素 ),成员函数 remove从集合中删除指定的元素 (如果集合中存在该元素 )。请编写成员函数 remove。在 main函数中给出了一组测试数据,此时程序的正确输出结果应为: 2 3 4 5 27 28 31 66 75 2 3 4 5 6 27 28 31 66 75 2 3 4 5 6 19 27 28 31 66 75 3 4 5 6 19 27 28 31 66 75 3 4 5 6 19 27 28 31 66
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 487 答案 解析 DOC
