[计算机类试卷]国家二级C++机试(操作题)模拟试卷291及答案与解析.doc
《[计算机类试卷]国家二级C++机试(操作题)模拟试卷291及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级C++机试(操作题)模拟试卷291及答案与解析.doc(6页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 291及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 proj1下的工程 proj1。程序中位于每个 “ ERROR *found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: value 63 number 1 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include iostream using namespace std; class MyClass int * P; const int N; public: ERROR *found* MyClass
2、(int val): N 1 P new int; *p val; ERROR *found* MyClass()delete * P; ) friend void print(MyClass&obj); ; ERROR *found* void MyClass print(MyClasS&obj) cout “value “ * (obj P) end1, cout “number “ obj N end1; int main() MyClass obj(63); print(obj); return 0; 二、简单应用题 2 请使用 VC6或使用【答题】菜单打开考生文件夹 proj2下的工
3、程 proj2,其中定义了 Component类、 Composite类和 Leaf类。 Component是抽 象基类, Composite和 kaLf是 Component的公有派生类。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: Leaf Node 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动 “ *found*”。 #include iostream using namespace std; clas s Component public: 声明纯虚函数 print() *found* ; clasS Composit
4、e: public Component public: *found* void setChild(_) m_child child; virtual void print()const m_child print(); private: Component * m_child; ; class Leaf: public Component public: virtual void print()const *found* ; int main() Leaf node; Compos ite comp; comp setChild(&node); Component * P ∁ P
5、print(); return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中 定义的 Matrix是一个用于表示矩阵的类。成员函数 max_value的功能是求出所有矩阵元素中的最大值。例如,若有 33矩阵 则调用 max_value函数,返回值为 3。请编写成员函数 max_valueo 要求: 补充编制的内容写在 “*333*”与 “ *666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out dat中。输出函数 wfiteToFile已经编译为 obj文件,并且在本程序中调用。 Matrix h#i
6、nclude iostream#include iomanip using namespace std; const int M 18; const int N 18; class Matrixint arrayMN; public: Matrix() int getElement(int i, int j)constreturn arrayij; void setElement(int i, intj, int。 value)arrayij value; ) int max value()const; void show(const char *s)const COUt end1 s; fo
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 机试 操作 模拟 291 答案 解析 DOC
