【计算机类职业资格】二级C++分类模拟117及答案解析.doc
《【计算机类职业资格】二级C++分类模拟117及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++分类模拟117及答案解析.doc(11页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+分类模拟 117 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.请使用 VC6 或使用【答题】菜单打开 proj1 下的工程 proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“/ ERROR *found*”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: The value is:10 注意:只修改注释“/ ERROR *found*”的下一行语句,不要改动程序中的其他内容。 / proj1.cpp #include iostream using namespace std; class
2、 Member / ERROR *found* private: Member(int val):value(val) int value; ; class MyClass Member _m; public: / ERROR *found* MyClass(int val) int GetValue() const return _m.value; ; int main() MyClass *obj = new MyClass (10); / ERROR *found* 下面语句输出 obj 指向类中的 value 值 cout “The value is:“ obj.GetValue()
3、endl; delete obj; return 0; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.请使用 VC6 或使用【答题】菜单打开 proj2 下的工程 proj2,该工程中含有一个源程序文件proj2.cpp,其中定义了 CharShape 类、Triangle 类和 Rectangle 类。 CharShape 是一个抽象基类,它表示由字符组成的图形(简称字符图形),纯虚函数 Show 用于显示不同字符图形的相同操作接口。Triangle 和 Rectangle 是 CharShape 的派生类,它们分别用于表示字符三角形和字符矩形,并且都定义了成员函数
4、 Show,用于实现各自的显示操作。程序的正确输出结果应为: * * * * # # # 请阅读程序,分析输出结果,然后根据以下要求在横线处填写适当的代码并删除横线。 (1)将 Triangle 类的成员函数 Show 补充完整,使字符三角形的显示符合输出结果。 (2)将 Rectangle 类的成员函数 Show 补充完整,使字符矩形的显示符合输出结果。 (3)为类外函数 fun 添加合适的形参。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“/ *found*”。 / proj2.cpp #include iostream using namespace st
5、d; class CharShape public: CharShape(char ch) : _ch(ch) ; virtual void Show() = 0; protected: char _ch; /组成图形的字符 ; class Triangle : public CharShape public: Triangle (char ch, int r) : CharShape(ch), _rows(r) void Show(); private: int _rows; /行数 ; class Rectangle: public CharShape public: Rectangle
6、(char ch, int r, int c) : CharShape (ch), _rows(r), _cols(c) void Show (); private : int _rows, _cols; /行数和列数 ; void Triangle:Show() /输出字符组成的三角形 for (int i = 1; i = _rows; i +) / *found* for (int j = 1; j =_; j +) cout _ch; cout endl; void Rectangle:Show() /输出字符组成的矩形 / *found* for (int i = 1; i =_;
7、i+) / *found* for (int j = 1; j =_; j+) cout _ch; cout endl; / *found* 为 fun 函数添加形参 void fun (_) cs. Show(); int main() Triangle tri (“*“, 4); Rectangle rect(“#“, 3, 8); fun(tri); fun(rect); return 0; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.请使用 VC6 或使用【答题】菜单打开 proj3 下的工程文件 proj3,此工程中包含一个源程序文件proj3.cpp,其
8、功能是从文本文件 in.dat 中读取全部整数,将整数序列存放到 intArray 类的对象中,然后建立另一对象 myArray,将对象内容赋值给 myArray。类 intArray 重载了“=”运算符。程序中给出了一个测试数据文件 input,不超过 300 个的整数。程序的输出是: 10 11 13 16 20 要求: 补充编制的内容写在“/ *333*”与“/ *666*”之间。实现重载赋值运算符函数,并将赋值结果在屏幕输出。格式不限。不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out.dat 中。输出函数 writeToFile 已经编译为 obj 文件,并且在本程序中
9、调用。 /intArray.h class intArray private: int * array; int length; public: intArray(char * filename); intArray(); intArray intArray(); void show(); ; void writeToFile(const char * path); /main.cpp #include iostream #include fstream #include cstring #include “intArray.h“ using namespace std; intArray:i
10、ntArray() length = 10; array = new intlength; intArray:intArray (char * filename) ifstream myFile(filename); array = new int300; length = 0; while(myFile arraylength +) length -; myFile.close(); intArray length = src.length; array = new intlength; / *333* / *666* return * this; intArray:intArray() d
11、elete array; void intArray:show() int step=0; for(int i=0; ilength; i=i+step) cout arrayi endl; step +; void main() intArray * arrayP = new intArray (“input.dat“); intArray myArray; myArray = * arrayP; (* arrayP).show(); delete arrayP; writeToFile(“ “); (分数:40.00)_二级 C+分类模拟 117 答案解析(总分:100.00,做题时间:9
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 分类 模拟 117 答案 解析 DOC
