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

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

1、国家二级 C+机试(操作题)模拟试卷 309及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modi1 cpp,该程序运行时有误,请改正其中的错误,使程序正常运行,并使程序在界面上输出为: 平均值为: 29 最大值为: 112 最小值为: -11 注意:错误的语句在 *error*的下面。修改该语句即可。 #include using namespace std; int main() int i, Ave, Min, Max; int data8=0, 112, 43, 78, -11, -6, 7, 9; Ave=0; for(i=0; iMin) Min=da

2、tai; cout int fun(int a, int n) Void main() int A=1, 2, 3, 4; cout class CMyTime private: *1* public: CMyTime(int year, int month) *2* void display() char yearChar3; char monthChar3; yearChar0= (m_year 100) 10+0; yearChar1= (m_year 10)+0; monthChar0 = (m_month 100) 10+0; monthChar1 = (m_month 10)+0;

3、 *3* coutMax)Max=datai; (3)if(dataiMax)Max=datai。 (3)同样如果数组该元素值比 Min小,则 Min取该元素值。因此,两个 if中条件判断错误,第 3标识处 “if(dataiMin)Min=datai”改成“if(datai0) return an-1+fun(a, n-1); 递归求 n项的和 return 0; 项数小于等于 0,返回求和值 0 【试题解析】 (1)如果要计算的项数小于等于 0,那么直接返回 0。 (2)否则调用递归语句 “an-1+fun(a, n-1)”,实现 0到第 n项的和。 三、综合应用题 3 【正确答案】 (1

4、)添加语句: int m year, m month; (2)添加语句: m year=year; m month=month; (3)添加语句: yearChar2 =0; monthChar2=0; (4)添加语句: m year+=m month 12;或 m year=m year+m month 12; 【试题解析】 (1)第 1个标识下添加 CMyTime的私有成员变量 m_year、m_month的声明,因此第 1个标识下应添加 “int m_year, m_month; ”。 (2)第 2个标识下完成类成员构造函数变量的初始化,即将参数分别赋值给m_year和 m_month,

5、因此第 2个标识下应添加 “m_year=year;m_month=month; ”。 (3)第 3个标识下准备输出 yearChar数组和 monthChar数组,字符数组的最后一个字符应该为 NULL(O),因此第 3个标识下应添加 “yearChar2=0;monthChar2=0; ”。 (4)m month和参数之和赋值给 m_month,其和可能超过 12,如果超过 12表示下一年了,因此 m_year应该加 1,故先判断 m_month是否比 12大,可取m_month 12和 m_year相加,如果 m_month没有超过 12则 m_month 12=0,反之则为 1,第 4标识下应添加 “m_year+=m_month 12;或m_year=m_year+m_month 12; ”。

展开阅读全文
相关资源
猜你喜欢
  • STAS SR ISO 6969-1995 Road vehicles - Sound signalling devices - Test after mounting on vehicle《道路车辆 音响信号装置 安装于车辆后测试 》.pdf STAS SR ISO 6969-1995 Road vehicles - Sound signalling devices - Test after mounting on vehicle《道路车辆 音响信号装置 安装于车辆后测试 》.pdf
  • STAS SR ISO 6987-2-1993 Indexable inserts for cutting tools Hardmetal (carbide) inserts with rounded corners with partly cylindrical fixing hole Part 2 Dimensions of inserts with 1.pdf STAS SR ISO 6987-2-1993 Indexable inserts for cutting tools Hardmetal (carbide) inserts with rounded corners with partly cylindrical fixing hole Part 2 Dimensions of inserts with 1.pdf
  • STAS SR ISO 6994-1995 Aluminium ores - Determination of aluminium content EDTA titrimetric method《铝矿石 铝含量的测定:乙二胺四乙酸滴定法 》.pdf STAS SR ISO 6994-1995 Aluminium ores - Determination of aluminium content EDTA titrimetric method《铝矿石 铝含量的测定:乙二胺四乙酸滴定法 》.pdf
  • STAS SR ISO 7083-1996 Technical drawings Symbols for geometrical tolerancing Proportions and dimensions《技术图纸 几何公差的符号 比例和尺寸》.pdf STAS SR ISO 7083-1996 Technical drawings Symbols for geometrical tolerancing Proportions and dimensions《技术图纸 几何公差的符号 比例和尺寸》.pdf
  • STAS SR ISO 7086-1-1996 Glassware and glass ceramic ware in contact with food -Release of lead and cadmium Part 1 Method of test《接触食品的玻璃器皿和玻璃陶瓷器皿 铅和镉的释放 第1部分:测试方法》.pdf STAS SR ISO 7086-1-1996 Glassware and glass ceramic ware in contact with food -Release of lead and cadmium Part 1 Method of test《接触食品的玻璃器皿和玻璃陶瓷器皿 铅和镉的释放 第1部分:测试方法》.pdf
  • STAS SR ISO 7086-2-1996 Glassware and glass ceramic ware in contact with food -Release of lead and cadmium Part 2 Permissible limits《接触食品的玻璃器皿和玻璃陶瓷器皿 铅和镉的释放 第2部分:允许的限度》.pdf STAS SR ISO 7086-2-1996 Glassware and glass ceramic ware in contact with food -Release of lead and cadmium Part 2 Permissible limits《接触食品的玻璃器皿和玻璃陶瓷器皿 铅和镉的释放 第2部分:允许的限度》.pdf
  • STAS SR ISO 7087-1995 Ferroalloys Experimental methods for the evaluation of the quality variation and methods for checking the precision of sampling《铁合金 评定质量波动的实验方法和检验取样精度的方法》.pdf STAS SR ISO 7087-1995 Ferroalloys Experimental methods for the evaluation of the quality variation and methods for checking the precision of sampling《铁合金 评定质量波动的实验方法和检验取样精度的方法》.pdf
  • STAS SR ISO 7097-1995 Determination of uranium in reactor fuel soiutions and in uranium product soiutions - Iron (II) sulfate reduction potassium dichromate oxidation titrimetric m.pdf STAS SR ISO 7097-1995 Determination of uranium in reactor fuel soiutions and in uranium product soiutions - Iron (II) sulfate reduction potassium dichromate oxidation titrimetric m.pdf
  • STAS SR ISO 7119-1995 Continuous mechanical handling equipment for loose bulk materials - Screw conveyors - Design rules for drive power《松散物料连续搬运设备 螺旋输送机 驱动功率设计规则 》.pdf STAS SR ISO 7119-1995 Continuous mechanical handling equipment for loose bulk materials - Screw conveyors - Design rules for drive power《松散物料连续搬运设备 螺旋输送机 驱动功率设计规则 》.pdf
  • 相关搜索

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

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