[计算机类试卷]国家二级C++机试(操作题)模拟试卷213及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷213及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷213及答案与解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 213及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1,此工程中包含了类 Pets(“宠物 ”)和主函数 main的定义。程序中位于每个 “ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name: sonny Type: dog Name: John Type: dog Name: Danny Type: cat Name: John Type: dog 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 1 #it
2、iclude 2 using namespace std; 3 4 enum Pets_typedog, cat, bird, fish; 5 class Pets 6 private: 7 char*name; 8 Pets_type type; 9 public: 10 Pets(const char*name=“sonny“, Pets_type type=dog); 11 Pets 12 PetS(); 13 void show()const; 14 ; 15 PetS: Pets(const char*name, Pets_type type) 16 构造函数 17 18 this-
3、name=new charstrlen(name)+1; 19 strcpy(this-name, name); 20 ERROR *found* 21 type=type; 22 23 Pets: Pets()析构函数,释放 name所指向的字符串 24 25 ERROR *found* 26 name= 0; 27 28 Pets Pets: operator=(const Pets s) 29 30 if( s=this)确保不要向自身赋值 31 return*this; 32 deletename; 33 name=new charstrlen(s name)+1; 34 ERROR
4、*found* 35 strcpy(this-name, name); 36 type=s type; 37 return*this; 38 39 void Pets: show()const 40 41 cout 2 using namespace std; 3 class Book “书 ”类 4 char*title;书名 5 int num pages; 页数 6 char*writer; 作者姓名 7 public: 8 Book(conSt char*the title, int pages, const char*the writer): num 9 pages(pages) 1
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 213 答案 解析 DOC
