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

上传人:花仙子 文档编号:497383 上传时间:2018-11-28 格式:DOC 页数:6 大小:33KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷305及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷305及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷305及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷305及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷305及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级 C+机试(操作题)模拟试卷 305及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹 proj1下的工程 proj1,其中有 “沙发 ”类 Sofa和主函数main的定义。程序中位于每个 ERROR *found*下的语句行有错误,请加以更正。更正后程序的输出应该是: 座位数: 3 颜色:红色 注意:只能修改每个 ERROR, *found*下的那一行,不要改动程序中的其他内容。 #include iost: ream using namespace st: d; class Sofa “沙发 ”类 int seats; 座位数 char color10;颜色 public

2、: ERROR*found* Sofa(int s,const char * co) ERROR*found* if(CO NULL) color0 0; else strcpy(color, co); ERROR*found* const char * getSeats()constreturn seats; ) const char * gel: Color()constreturn color; ) ; int: main() Sofa sara(3); cout: “座位数: ” sara getSeats() end1; cout: “颜色: ” sara getColor() en

3、d1; return 0; 二、简单应用题 2 使用 VC6打开考生文件夹 proj2下的工程 proj2,其中有元素类 Element和队列类 Queue的定义。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的输出结果应为: 3 8 5 0 5 0 7 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。 #include iostream #include cmath #include cstdlib using namespace std; #define MaxLength 100 class Element: “元素 ”类 public: int n

4、; Element: (int i 0): n(i) ; class Queue “队列 ”类 Element * element; 指向存储元素的数组的指针 int tail;队尾元素的下标 public: Queue(): element(new Elemerit; 100), tail( 1) Queue()deleteelement; void push(Element ele); 在队列尾端添加一个元素 Element pop(); 在队列首端删除一个元素,返回被删元素 Element ffont()constEeturn element: 0; 返回队首元素,但不从队列中删除该元素

5、 *found* int size()constreturn(_); 返回元素个数 void show()const; 显示集合中所有元素 ; void Queue push (Elementele) if(tail HaxLength 1) return;空间满,不做任何处理 *found* _; Element Queue pop() if(size() 0)exit(1); 队列空,不做任何处理 Element tmp element0; for(int i 0; i tail; i ) elementi elementi+1; *found* _; return trnp; void

6、Queue show()COnst *found* for(_) cout elementi n ; cout end1; int main() Queue q; q push(3); q push(8); q push(5); q push(0); q show(); q pop(); q pop(); q push(7); q show(); return 0; 三、综合应用题 3 使用 Vc6打开考生文件夹 proj3下的工程 proj3,其中声明了 NyString类,它是一个用于表示字符串的类。成员函数 reverse将字符串反转,例如 “abode”反转后就成了 “edcba”。请

7、补充完整函数 reverse。在 main函数中给出了一个测试数据,此情况下程序的输出应该是: This is a string gnirtS a si sihT 注意:只需在函数 reverse的 *333*和*666*之间填入若干语句,不要改动程序中的其他内容。 NyString h #include iostream usirig namespace std; char * dup(const char *); class NyString char * str; public: NyString(const char * s “): str(dup(s) NyString(const

8、NyString&m): str(dup(m str) HySting()deletestr; void reverse(); void show(ostream&os tout) constos str end1; ) ; inline ostream&operator fostrearn& os, const NyString&m) m show(os); return os; void writeTOFile(const char * path); NyString cpp #include“NyString h“ char * clup(const ohar * s) char * p

9、 new charstrlen(s) 1; strcpy(p, s); return p; void NyString EeveEse() *333* *666* void writeToFile(const char *path); writetoFile cpp #include fstream #include“MyString h“ void writeToFile(const char *path) char full150; strcpy(full, path); Strcat(full, “out dat“); OfStream outfile(full); if(outfile

10、 fail()cerr “打开输出文件失败 !“; return; MyString m1: “This is another string“; MyString m2(“字符串反转演不 “); outfile m1 m2: m1 reverse(); m2 reverse(); outfile m1 m2; outfile close(); 国家二级 C+机试(操作题)模拟试卷 305答案与解析 一、基本操作题 1 【正确答案】 (1)Sofa(int s, const char * co “红色 ”): seats(s) (2)if(co NULL) (3)int getSeats()constreturn seats; 二、简单应用题 2 【正确答案】 (1)tail 1 (2)element tail ele (3)tail (4)int i 0; i tail; i 三、综合应用题 3 【正确答案】 void MyString reverse() int i, i; char ch; int len strlen(str); for(i 0, j len 1; i j; i, j ) ch stri; stri strj; strj ch;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

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