[计算机类试卷]国家二级C++机试(操作题)模拟试卷130及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷130及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷130及答案与解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 130及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 projl,此工程中包含一个源程序文件 main cpp,其中有类 B00k(“书 ”)和主函数 main的定义。程序中位于每个 “ ERROR*found*”下的语句行有错误,请加以改正。改正后程序的输出结果应该是: 书名: C+语句程序设计总页数: 299 已把 “c+语言程序设计 ”翻到第 50页 已把 “C+语言程序设计 ”翻到第 51页 已把 “C+语言程序设计 ”翻到第 52页 已把 “C+语言程序设计 ”翻到第 51页 已把书合上。 当
2、前页: 0 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include using namespace std; class Book char*title; int num_pages;页数 int cur_page;当前打开页面的页码, 0表示书未打开 public: ERROR*found* Book(const char*theTitle, int pages)num_pages(pages) title=new charstrlen(theTi-tle)+1; strcpy(title, theTitle); coutnum_pages)
3、 cout using namespace std; class Room “房间 ”类 int room no; 房 间号 double length; 房间长度 (m) double width; 房间宽度 (m) public: Room(int the room no, double the length, double thewidth): roomno (theroomno), length(thelength), width(the_width) int theRoomNo()constreturn room no; 返回房间号 double theLength()const f
4、 return length; 返回房间长度 double theWidth()constreturn width; 返回房间宽度 *found* double theArea()const) 返回房间面积 (矩形面积 ) ); class Office: public Room “办公室 ”类 chardepart; 7甄属部 n public: Office(int the room no, double the length, double thewidth, const char*the depart) *found* : _ depart=new char strlen(the de
5、part)+1 j; *found* strcpy(_); 一 Office()deletedepart; ) const char*theDepartment()const return depart; )返回所属部门 , int main() * found* Office_;: cout #include using namespace std; class MiniString public: friend ostream&operator(is。 tream&input, MiniString s) 重载流提取运算符 char temp100;用于输入的临时数组 temp0=0;初始
6、为空字符串 inputsetw(100)temp; int inLen=strlen(temp); 输入字符每长度 if(inLen!=0) S 1ength=inLen; 赋长度 if(S sPtr!=0)deleteS sPtr;避免内存泄漏 S sPtr=new charS 1ength+1; strcpy(S sPtr, temp); 如果 S不是空指针,则复制内容 else S sPtr0= 0; 如果 S是空指针,则为空字符串 return input; void modString( const char* string2)更改字符串内容 if(string2 !=0) 如果 s
7、tring2不是空指针,则复制内容 if(strlen(string2)!=length) length=strlen(string2); deletesPtr; sPtr=new char1ength+1; 分配内备 strcpy(sPtr, string2); else sPtr0= 0; 如果 string2是空指针,则为空字符串 MiniString operator=(const Mini。 String otherString); MiniString(const char*S = ”): length(S!=0)?strlen(S): 0) 构造函数 SPtr=0; if(1en
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 130 答案 解析 DOC
