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

上传人:orderah291 文档编号:497491 上传时间:2018-11-28 格式:DOC 页数:5 大小:30.50KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷402及答案与解析.doc_第1页
第1页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷402及答案与解析.doc_第2页
第2页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷402及答案与解析.doc_第3页
第3页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷402及答案与解析.doc_第4页
第4页 / 共5页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷402及答案与解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C+机试(操作题)模拟试卷 402及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modil cpp,该程序运行时有错误,请改正程序中的错误,使得程序输出: 1, 2, 3, 4, 5, 注意:不要改动 main函数,不能增行或删行,也不能更改程序的结构,错误的语句在 *error*的下面。 #include class TestClass *error* TestClass(int i) m_i = i; void print() cout5) *error* i+; data print(); cout void fun(double b, int l

2、en) void main() double b128; fun(b, 128); for(int i=0; i class Date public: *2* Date(int y, int m, int d) *3* void print()const; private: data member *1* ; void Date: print()const *4* int main() Date national_day(1949, 10, 1); national_day print(); return 0; 国家二级 C+机试(操作题)模拟试卷 402答案与解析 一、基本操作题 1 【正确

3、答案】 (1)public: TestClass(int i) (2)int i(10); (3)i-; 【试题解析】 (1)打开 moid1 cpp调试程序,显示错误提示为第一标识下“modi1 cpp(20): error C2248: TestClass: TestClass: cannot access private memberdeclared in class“TestClass“,提示类 TestClass中的构造函数 TestClass被定义为私有的,无法获得,所以这里应该是 public,即 “public: TestClass(int i)”。 (2)题目中要求输出结果为

4、 1, 2, 3, 4, 5,即循环 5次。第三个表示 while循环条件是 i大于 5就进行循环。 “int i(); ”应该实现变量 i的初始化,题干中要求不能删除 i初始化中的括号,所以在括号中添加 i的初始值。大 于 5且循环 5次,所以 i的初始值为 10,而 while循环中对 i的操作应该是 i-,这样第二个和第三个标示下应该是 “int i(10); ”和 “i-; ”。 二、简单应用题 2 【正确答案】 if(len0)最小值位置 b0=0; 赋值第一个元素 if(len1) b1=1; 赋值第二个元素 for(int i=2; ilen; i+) bi=bi 1+bi-2;

5、将两个元素之和赋予当前元素 【试题解析】 (1)判断数组长度,如果存在第一个元素,那么将第一个元 素赋值为 0,即 b0=0;。 (2)然后再判断数组长度,如果存在第二个元素,那么将第二个元素赋值为 1,即b1=1;。 (3)最后从第三个元素到数组最后一个元素,赋直 bi=bi 1+bi 2;。 三、综合应用题 3 【正确答案】 (1)添加语句: int year, month, day; (2)添加语句: Date()year=1; month=1; day=1; (3)添加语句: year=y; month=m; day=d; (4)添加语句: coutyear“-“month“-“day

6、end1; 【试题解析】 (1)题目 1要求 “定义私有数据成员 year、 month和 day,分别用于表示年、月和日,它们都是 int型的数据 ”。在 C+程序的 privte区域中添加变量year、 month、 day的定义,即在第 1个标识下添加 “int year, month, day; ”。 (2)题目 2要求 “完成默认构造函数 Date的定义,使 Date对象的默认值为:year=1, month=1, day=1”。在 C+中,构造函数是一种特殊的成员函数,它的名字与类同名。在 Date构造函数体内,根据 题目要求,设置变量默认值“year=1, month=1, da

7、y=1”,即: “Date()year=1; month=1; day=1; ”。 (3)题目 3要求 “完成重载构造函数 Date(int y,intm, int d)的定义,把数据成员year、 month和 day分别初始化为参数 y、 m和 d的值。 ”在构造函数 Date(inty,int m,int d)的函数体内,即标识 3下,添加赋值语句,将 y, m, d赋值给 year,month, day,即 “year=y; month=m; day=d; ”。 (4)题目 4要求 “完成 成员函数 print()的类外定义,使其以 “年一月一日 ”的格式将Date对象的值输出到屏幕上 ”。在程序中的 void Date: print() const函数体内,标识 4下,添加输出语句。根据 cout输出格式,实现题目中的输出要求, 即“coutyear“-“month“-“dayend1; ”。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 2591-D19-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D19 - Stability of Male Contacts in Insert (Issue P 1)《航空航天系列 电气和光学连接部件.pdf ASD-STAN PREN 2591-D19-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D19 - Stability of Male Contacts in Insert (Issue P 1)《航空航天系列 电气和光学连接部件.pdf
  • ASD-STAN PREN 2591-D2-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D2 - Shock (Issue P 1)《航空航天系列 电气和光学连接部件 试验方法 第D2部分 冲击 第P1版》.pdf ASD-STAN PREN 2591-D2-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D2 - Shock (Issue P 1)《航空航天系列 电气和光学连接部件 试验方法 第D2部分 冲击 第P1版》.pdf
  • ASD-STAN PREN 2591-D20-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D20 - Mechanical Strength of Rear Accessories (Issue P 1)《航空航天系列 电气和光学连.pdf ASD-STAN PREN 2591-D20-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D20 - Mechanical Strength of Rear Accessories (Issue P 1)《航空航天系列 电气和光学连.pdf
  • ASD-STAN PREN 2591-D24-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D24 - Stripping Force Solderless Wrapped Connections (Issue P 1)《航空航天系列.pdf ASD-STAN PREN 2591-D24-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D24 - Stripping Force Solderless Wrapped Connections (Issue P 1)《航空航天系列.pdf
  • ASD-STAN PREN 2591-D25-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D25 - Unwrapping Solderless Wrapped Connections (Issue P 1)《航空航天系列 电气和光.pdf ASD-STAN PREN 2591-D25-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D25 - Unwrapping Solderless Wrapped Connections (Issue P 1)《航空航天系列 电气和光.pdf
  • ASD-STAN PREN 2591-D26-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D26 - Contact Retention System Effectiveness (Removable Contact Walkout.pdf ASD-STAN PREN 2591-D26-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D26 - Contact Retention System Effectiveness (Removable Contact Walkout.pdf
  • ASD-STAN PREN 2591-D27-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D27 - Robustness of Protective Cover Attachment (Issue P 1)《航空航天系列 电气和光.pdf ASD-STAN PREN 2591-D27-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D27 - Robustness of Protective Cover Attachment (Issue P 1)《航空航天系列 电气和光.pdf
  • ASD-STAN PREN 2591-D28-1993 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D28 - Sinusoidal Vibrations with Passage of Current for Lugs and in-Lin.pdf ASD-STAN PREN 2591-D28-1993 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D28 - Sinusoidal Vibrations with Passage of Current for Lugs and in-Lin.pdf
  • ASD-STAN PREN 2591-D4-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D4 - Transverse Load (External Bending Moment) (Issue P 1)《航空航天系列 电气和光学连.pdf ASD-STAN PREN 2591-D4-1992 Aerospace Series Elements of Electrical and Optical Connection Test Methods Part D4 - Transverse Load (External Bending Moment) (Issue P 1)《航空航天系列 电气和光学连.pdf
  • 相关搜索

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

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