【计算机类职业资格】二级C++-68及答案解析.doc
《【计算机类职业资格】二级C++-68及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++-68及答案解析.doc(4页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+-68及答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1。此工程中包括类 Point、函数fun和主函数 main。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: The point is(0,1) The point is(3,5) 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace st
2、d; class Point public: / ERROR *found* Point(int x = 0, int y) : x_(x), y_(y) / ERROR * found* void move(int xOff, int yOff) const x_+ = xOff; y_+ = yOff; void print() const cout “The point is (“ x_, y_ ) endl; private: int x_, y_; ; void fun (Point* p) /ERROR * found* p.print (); int main () Point
3、p1, p2 (2, 1); p1.print (); p2.move (1, 4); fun ( return 0; (分数:30.00)_二、B简单应用题/B(总题数:1,分数:30.00)2.请使用 VC6或使用答题菜单打开考生文件夹 proj2下的工程 proj2。其中的 Collection定义了集合类的操作接口。一个集合对象可以包含若干元素。工程中声明的 Array是一个表示整型数组的类,是Collection的派生类,它实现了 Collection中声明的纯虚函数。Array 的成员说明如下: 成员函数 add用于向数组的末尾添加一个元素; 成员函数 get用于获取数组中指定位置
4、的元素; 数据成员 a表示实际用于存储数据的整型数组; 数据成员 size表示数组的容量,数组中的元素个数最多不能超过 size; 数据成员 num表示当前数组中的元素个数。 请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为: 1,2,3,4,5,6,7,8,9,10, 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“/*found*”。 #include iostream using namespace std; /集合类的操作接口 class Collection public: virtual void add (int e)
5、 = 0; /获取指定位置的元素 virtual int get (unsigned int i) const = 0; ; /实现了集合接口 class Array : public Collection public: Array (unsigned int s) /* found* a = new _; size = s; num: 0; Array ( ) /* found* _: virtual void add (int e) if (num size) /* found* _=e; num +; virtual int get ( unsigned int i) const if
6、 (i size) /* found* _; return 0; private: int * a; unsigned int size; unsigned int hum; ; void fun (Collection for (i = 0; i 10; i+) col.add (i+1); for (i = 0; i10; i+) cout col.get(i) “,“; cout endl; int main () Array a (0xff); fun (a); return 0; (分数:30.00)_三、B综合应用题/B(总题数:1,分数:40.00)3.请使用 VC6或使用答题菜
7、单打开考生文件夹 proj3下的工程 proj3,其中定义的 MyString类是一个用于表示字符串的类。假设字符串由英文单词组成,单词与单词之间使用一个空格作为分隔符。成员函数wordCount的功能是计算组成字符串的单词的个数。 例如,字符串“dog”由 1个单词组成;字符串“the quickbrown fox jumps over the lazy dog”由 9个单词组成。请编写成员函数 wordCount。在main函数中给出了一组测试数据,此时程序应显示: 读取输入文件. STR1=1 STR2=9 要求: 补充编制的内容写在“/*333*”与“/*666*”之间,不得修改程序的
8、其他部分。注意:程序最后将结果输出到文件 out.dat中。输出函数 WriteToFile已经编译为 obj文件,并且在本程序中调用。 /mystring.h #include iostream #include string.h using namespace std; class MyString public: MyString(const char* s) str = new charstrlen(s)+1; strcpy(str, s); MyString() delete str; int wordCount() const; private: char * str; ; voi
9、d writeToFile(char * , int); /main.cpp #include fstream #include “mystring.h“ int MyString:wordCount() const /* 333* /* 666* int main() char inname128, pathname80; strcpy(pathname, “); sprintf (inname, “in. dat“, pathname); cout “读取输入文件. /n/n“; ifstream infile (inname); if (infile.fail () cerr “打开输入
10、文件失败!“; exit(1); char buf4096; infile.getline(buf, 4096); MyString str1 (“dog“), str2 (“the quick brown fox jumps over the lazy dog“), str3 (buf); str1.wordCount (); cout “STRI = “ str1.wordCount () endl; cout “STR2 = “ str2.wordCount() endl endl; writeToFile(pathname,str3.wordCount(); return 0; (分数
11、:40.00)_二级 C+-68答案解析(总分:100.00,做题时间:90 分钟)一、B基本操作题/B(总题数:1,分数:30.00)1.请使用 VC6或使用答题菜单打开考生文件夹 proj1下的工程 proj1。此工程中包括类 Point、函数fun和主函数 main。程序中位于每个“/ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: The point is(0,1) The point is(3,5) 注意:只修改每个“/ERROR *found*”下的那一行,不要改动程序中的其他内容。 #include iostream using names
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 C68 答案 解析 DOC
