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

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

1、国家二级 C+机试(操作题)模拟试卷 79及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modil cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: 1 5 1 注意:错误的语句在 *error*的下面,修改该语句即可。 #include *error* enum Sun, Mon, Tue, Wed, Thu, Fri, Sat, *error* MyEnum; struct Struct *error* int Fri, int Sun; ; void main() int i=Mon; MyEnum t=Fri ; Struct strl

2、 strl Fri=Mon; cout int num(char*str) int main() char str1024; cout using namespace std; class CBase public: CBase(int i)b=i ; *1* protected: int b; ; class CDerive: publ ic CBase public: *2* void display() coutdisplay(); void main() *4* func(d1); func(d2); 国家二级 C+机试(操作题)模拟试卷 79答案与解析 一、基本操作题 1 【正确答

3、案】 (1)enum MyEnum (2) ; (3)int Fri; 【试题解析】 (1)第一标识下声明枚举类型,声明枚举类型的一般形式为:“enum; ”,程序当中把枚举类型名 MyEnum放到枚举声明后面,显然不符合枚举类型声明格式,因此第 1个标识下应改成“enumMyEnum”。 (2)由 (1)的分析可知,第 2个标识下也不符合枚举类型声明格式,应以 “; ”结束,即第 2个标识下应改为 “; ”。 (3)第 3标识处声明结构体,结构体定义的一般形式为: struct ; 结构体中成员列表中各个元素是不同的变量,变量之间应以分号隔开,而不是以逗号隔开,因此第 3个标识下应改为为 “

4、int Fri; 990 二、简单应用题 2 【正确答案】 int number=0 ; for(int i=0 ; stri!=0 ;i+) if(stri9 stri9stri()=0,因此第 1个标识下应添加 “virtual void display0=0; ”. (2)类 CDerive的构造函数用来完成类成员变量的初始化,派生类没有自己的成员变量,可直接采用基类的构造函数完成初始化,因此第 2个标识下应添加“CDerive(inti): CBase(i)”0 (3)第 3个标识下是完成类 CDerive2成员函数 diaplayO的定义和实现,根据要求的输出结果 “In CDeri

5、ve2sdisplay() b=2”可知 display()函数除输出字符串“111CDerive2s display() ”还输出变量 b的值,故第 3个标识下应添加 “void display()cout”In CDerive2S display() “”b=”bendl; )”。 (4)在第 4个标识下应定义变量 dl和 d2, funcO函数的参数为 CBase对象指针,因此 d1和 d2均为 CBase对象指针,最终的输出结果 b分别为 1和 2,这两个对象指针分别指向 CDerive对象和 CDerive2对象,且初始化值分别为 1和 2,故第 4个标识下应添 加 “CDerive*d1=new CDerive(1): CDmive2*d2=new CDerive2(2); ”,在 C+中,一个基类指针 (或引用 )可以用于指向它的派生类,而且通过这个指针 (或引用 )调用虚函数,被调用的是该指针 (或引用 )实际指向的对象类的重定义版本,即 CDerive和 CDerive2均有成员函数 display(),在屏幕上打印结果。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 2243-2-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 2 Peel Metal-Metal Edition P 1《航空航天系列非金属物质结构用粘结剂.第2部分 剥离金属.P1版》.pdf AECMA PREN 2243-2-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 2 Peel Metal-Metal Edition P 1《航空航天系列非金属物质结构用粘结剂.第2部分 剥离金属.P1版》.pdf
  • AECMA PREN 2243-3-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 3 Peeling Test Metal-Honeycomb Core Edition P 1《航空航天系列非金属物质结构用粘结剂.第3部分 剥离试验用金属-.pdf AECMA PREN 2243-3-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 3 Peeling Test Metal-Honeycomb Core Edition P 1《航空航天系列非金属物质结构用粘结剂.第3部分 剥离试验用金属-.pdf
  • AECMA PREN 2243-4-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 4 Metal-Honeycomb Core Flatwise Tensile Test Edition P 1《航空航天系列非金属物质结构用粘结剂.第4部分.pdf AECMA PREN 2243-4-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 4 Metal-Honeycomb Core Flatwise Tensile Test Edition P 1《航空航天系列非金属物质结构用粘结剂.第4部分.pdf
  • AECMA PREN 2243-5-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 5 Ageing Tests Edition P 1《航空航天系列非金属物质结构用粘结剂.第5部分 老化试验.P1版》.pdf AECMA PREN 2243-5-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 5 Ageing Tests Edition P 1《航空航天系列非金属物质结构用粘结剂.第5部分 老化试验.P1版》.pdf
  • AECMA PREN 2243-6-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 6 Determination of Shear Stress and Shear Strain Edition P 2《航空航天系列非金属物质结构用粘结剂..pdf AECMA PREN 2243-6-2001 Aerospace Series Non-Metallic Materials Structural Adhesives Test Method Part 6 Determination of Shear Stress and Shear Strain Edition P 2《航空航天系列非金属物质结构用粘结剂..pdf
  • AECMA PREN 2245-1984 Pipelines for Liquids and Gases Definitions Aerospace Series Edition 2《液体和气体管道定义2版》.pdf AECMA PREN 2245-1984 Pipelines for Liquids and Gases Definitions Aerospace Series Edition 2《液体和气体管道定义2版》.pdf
  • AECMA PREN 2247-1977 Steel FE-PL43S 650 MPa Less Than or Equal to Rm Less Than or Equal to 850 MPa Tubes for Structures 0 5 mm Less Than or Equal to a Less Than or Equal to 12 mm dd.pdf AECMA PREN 2247-1977 Steel FE-PL43S 650 MPa Less Than or Equal to Rm Less Than or Equal to 850 MPa Tubes for Structures 0 5 mm Less Than or Equal to a Less Than or Equal to 12 mm dd.pdf
  • AECMA PREN 2251-1977 Steel FE-PL52 S Rm Greater Than or Equal to 700 MPa Tubes for Structures 0 8 mm Less Than or Equal to a Less Than or Equal to 12 5 mm d Greater Than or Equal t.pdf AECMA PREN 2251-1977 Steel FE-PL52 S Rm Greater Than or Equal to 700 MPa Tubes for Structures 0 8 mm Less Than or Equal to a Less Than or Equal to 12 5 mm d Greater Than or Equal t.pdf
  • AECMA PREN 2252-1977 Steel FE-PL52 S 1080 MPa Less Than or Equal to Rm Less Than or Equal to 1250 MPa Hand and Die Forgings De Less Than or Equal to 100 mm Aerospace Series Edition.pdf AECMA PREN 2252-1977 Steel FE-PL52 S 1080 MPa Less Than or Equal to Rm Less Than or Equal to 1250 MPa Hand and Die Forgings De Less Than or Equal to 100 mm Aerospace Series Edition.pdf
  • 相关搜索

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

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