[计算机类试卷]国家二级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循环来遍历数组中 的所有元素。 【解题宝典】主要考查考生对二维数组的掌握,二维数组使得存储的数据大幅增加,只要把二维数组想象成矩阵,利用矩阵相关知识求解即可。

展开阅读全文
相关资源
猜你喜欢
  • ASHRAE QC-06-006-2006 Geothermal Standing Column Wells Ten Years in a New England School《地热常设栏水井 在新英格兰地区的学校10年》.pdf ASHRAE QC-06-006-2006 Geothermal Standing Column Wells Ten Years in a New England School《地热常设栏水井 在新英格兰地区的学校10年》.pdf
  • ASHRAE QC-06-007-2006 Estimating Energy Demand and Cost Savings from a Geothermal Heat Pump ESPC Project Through Utility Bill Analysis《从一个通过公用事业费账单分析的地热热泵ESPC项目 估算能源 需求 并节省成本》.pdf ASHRAE QC-06-007-2006 Estimating Energy Demand and Cost Savings from a Geothermal Heat Pump ESPC Project Through Utility Bill Analysis《从一个通过公用事业费账单分析的地热热泵ESPC项目 估算能源 需求 并节省成本》.pdf
  • ASHRAE QC-06-008-2006 Transient Temperature Measurements and Characteristics for Temperature Sensors and Energy Wheels《瞬态温度测量和温度传感器和能量周期的特征》.pdf ASHRAE QC-06-008-2006 Transient Temperature Measurements and Characteristics for Temperature Sensors and Energy Wheels《瞬态温度测量和温度传感器和能量周期的特征》.pdf
  • ASHRAE QC-06-009-2006 Relationship between Energy Wheel Speed and Effectiveness and its Transient Response Part 1 Mathematical Development of the Characteristic Time Constants and .pdf ASHRAE QC-06-009-2006 Relationship between Energy Wheel Speed and Effectiveness and its Transient Response Part 1 Mathematical Development of the Characteristic Time Constants and .pdf
  • ASHRAE QC-06-010-2006 Relationship between Energy Wheel Speed and Effectiveness and its Transient Response Part II Comparison Between Mathematical Model Predictions and Experimenta.pdf ASHRAE QC-06-010-2006 Relationship between Energy Wheel Speed and Effectiveness and its Transient Response Part II Comparison Between Mathematical Model Predictions and Experimenta.pdf
  • ASHRAE QC-06-011-2006 Solar Heat Gain Coefficient Measurements for Glazings with Indoor Window Attachment Products《玻璃与室内窗附属产品的太阳热增益系数测量》.pdf ASHRAE QC-06-011-2006 Solar Heat Gain Coefficient Measurements for Glazings with Indoor Window Attachment Products《玻璃与室内窗附属产品的太阳热增益系数测量》.pdf
  • ASHRAE QC-06-012-2006 Monitored Energy Performance of Electrochromic Windows Controlled for Daylight and Visual Comfort《为日光和视觉舒适度的电变色窗户控制的能源性能的监察》.pdf ASHRAE QC-06-012-2006 Monitored Energy Performance of Electrochromic Windows Controlled for Daylight and Visual Comfort《为日光和视觉舒适度的电变色窗户控制的能源性能的监察》.pdf
  • ASHRAE QC-06-013-2006 Solar Heat Gain Coefficients for High-Mass Glazing Blocks《大的玻璃块的太阳热增益系数》.pdf ASHRAE QC-06-013-2006 Solar Heat Gain Coefficients for High-Mass Glazing Blocks《大的玻璃块的太阳热增益系数》.pdf
  • ASHRAE QC-06-014-2006 Real-Time Prediction of Rack-Cooling Performance《机架冷却性能的实时预报》.pdf ASHRAE QC-06-014-2006 Real-Time Prediction of Rack-Cooling Performance《机架冷却性能的实时预报》.pdf
  • 相关搜索

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

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