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

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

1、国家二级 C+机试(操作题)模拟试卷 135及答案与解析 一、基本操作题 1 请使用 VC6或使用【答题】菜单打开考生文件夹 projl下的工程 pmj1。程序中位于每个 “ ERROR*found*”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: value=63 number=1 注意:只修改每个 “ ERROR*found*”下的那一行,不要改动程序中的其他内容。 #include USing namespace std; class MyClass int*P; const int N; public: ERROR*found* MyClass(int val): N=1

2、 P=new int; P=val; ) ERROR*found* MyClass()delete*P; friend void print(MyClass obj); ; ERROR*found* void MyClass: print(MyClass obj) cout using namespace std; class Component public: 声明纯虚函数 print() *found* ; class Composite: public Component public: *found* void setChild(_) m child=chiid; virtual vo

3、id print()const m child一 print(); private: Component*mchild; ; class Leaf: public Component public: virtual void print()cons t *found* _ ; int main() Leaf node; Composite comp; comp setChild(&node); Component*P=∁ P一 print(); return 0; 三、综合应用题 3 请使用 VC6或使用【答题】菜单打开考生文件夹 proj3下的工程 proj3,其中定义的 Matr

4、ix是一个用于表示矩阵的类。成员函数 max_value的功能是求出所有矩阵元素中的最大值。例如,若有 33矩阵则调用 max_value函数,返回值为 3。请编写成员函数 maxvalueo 要求: 补充编制的内容写在 “ *333*”与 “*666*”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件 out dat中。输出函数 writeToFile已经编译为obj文件,并且在本程序中调用。 Matrix h #include #include us ing namespace std; const int M=18; const int N=18; class Matrix

5、 int arrayMN; public: Matrix() int getElement(int i, int J)const return arrayiJ; ) void setElement(int i, int J, int value)arrayiJ=value; ) int max value()const; void show(const char*s)const cout void readFromFile(const char*f, Matrix&m) ifstream infile(f); if(infile fail()cerrk; m setElement(i, j,

6、k); int Matrix: max value()const *333* *666* int main() Matrix m; readFromFile(“”, m); m show(“Matrix: ”); coutprint(); 第一条和第二条语句都是定义语句,第三条语句调用函数 setChild,由 setChild函数的定义可知, comp中的 mchild等于 node,第四条语句定义了个指针 p指向comp的地址,也就是 node,最后一条语句通过指针 p调用函数 print,也就是调用类 Leaf的函数 print,因为题目要求输出: Leaf Node,因此在这里添加语句

7、cout”Leaf Nodeendl;。 三、综合应用题 3 【正确答案】 Int temp; 定义整数变量 temp,并赋值为零 for(int i=0; iM; i+) 遍历矩阵的行 for(int j =0; j N; j+) 遍历短阵的列 if(temparrayij) 如果 temp小于 arrayij temp=arrayij; 把 arrayij赋值给 temp return temp; 返回 temp 【试题解析】 本题考查 Matrix类,其中涉及构造函数、二维数组、成员函数和const函数。 【解题思路】 主要考查考生对二维数组的掌握,题目要求成员函数 maxvalue的功能是求出所有矩阵元素中的最大值。因此只要逐个元素比较即可,下标 i和 j作为矩阵行和列的标记,使用双层 for循环来遍历数组中 的所有元素。 【解题宝典】主要考查考生对二维数组的掌握,二维数组使得存储的数据大幅增加,只要把二维数组想象成矩阵,利用矩阵相关知识求解即可。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 4003-2002 Aerospace Series Aluminium Alloy Al-P2219-T87 Sheet and Strip 0 5 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P2219-T87.pdf ASD-STAN PREN 4003-2002 Aerospace Series Aluminium Alloy Al-P2219-T87 Sheet and Strip 0 5 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P2219-T87.pdf
  • ASD-STAN PREN 4004-2002 Aerospace Series Aluminium Alloy AL-P3103-H16 Sheet and Strip 0 4 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P3103-H16.pdf ASD-STAN PREN 4004-2002 Aerospace Series Aluminium Alloy AL-P3103-H16 Sheet and Strip 0 4 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P3103-H16.pdf
  • ASD-STAN PREN 4005-2002 Aerospace Series Aluminium Alloy AL-P5052-O Sheet and Strip 0 3 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P5052-O制0 3.pdf ASD-STAN PREN 4005-2002 Aerospace Series Aluminium Alloy AL-P5052-O Sheet and Strip 0 3 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P5052-O制0 3.pdf
  • ASD-STAN PREN 4006-2002 Aerospace Series Aluminium Alloy AL-P6082-T4 or T42 Sheet and Strip 0 4 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P60.pdf ASD-STAN PREN 4006-2002 Aerospace Series Aluminium Alloy AL-P6082-T4 or T42 Sheet and Strip 0 4 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P60.pdf
  • ASD-STAN PREN 4007-2003 Aerospace Series Aluminium Alloy AL-P6082-T6 or T62 Sheet and Strip 0 4 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P60.pdf ASD-STAN PREN 4007-2003 Aerospace Series Aluminium Alloy AL-P6082-T6 or T62 Sheet and Strip 0 4 mm Less Than or Equal to a Less Than or Equal to 6 mm (Edition P 2)《航空航天系列 铝合金AL-P60.pdf
  • ASD-STAN PREN 4008-001-1998 Aerospace Series Elements of Electrical and Optical Connection Crimping Tools and Associated Accessories Part 001 Technical Specification (Edition P 1)《.pdf ASD-STAN PREN 4008-001-1998 Aerospace Series Elements of Electrical and Optical Connection Crimping Tools and Associated Accessories Part 001 Technical Specification (Edition P 1)《.pdf
  • ASD-STAN PREN 4008-002-1998 Aerospace Series Elements of Electrical and Optical Connection Crimping Tools and Associated Accessories Part 002 List of Product Standards (Edition P 1.pdf ASD-STAN PREN 4008-002-1998 Aerospace Series Elements of Electrical and Optical Connection Crimping Tools and Associated Accessories Part 002 List of Product Standards (Edition P 1.pdf
  • ASD-STAN PREN 4008-003-2015 Aerospace series Elements of electrical and optical connection Crimping tools and associated accessories Part 003 Positioner for crimping tool M22520 2-.pdf ASD-STAN PREN 4008-003-2015 Aerospace series Elements of electrical and optical connection Crimping tools and associated accessories Part 003 Positioner for crimping tool M22520 2-.pdf
  • ASD-STAN PREN 4008-004-2015 Aerospace series Elements of electrical and optical connection Crimping tools and associated accessories Part 004 Die for crimping tool M22520 5-01 Prod.pdf ASD-STAN PREN 4008-004-2015 Aerospace series Elements of electrical and optical connection Crimping tools and associated accessories Part 004 Die for crimping tool M22520 5-01 Prod.pdf
  • 相关搜索

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

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