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

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

1、国家二级( C+)机试模拟试卷 58及答案与解析 一、程序改错题( 30分) 1 使用 VC6打开考生文件夹下的工程 test28_1,此工程包含一个源程序文件test28_1.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果为: 5 5 源程序文件 test28_1.cpp清单如下: #include iostream.h class A public: /* found * static int n=1; A()n+; A() (n-; ; /* found * int n=0; int main() A a; A b3; A *c=new A; c= /* found

2、 cout c.n end1; cout A:n end1; return 0; 二、简单应用题( 40分) 2 请编写一个函数 sortnum(int num),参数 num是一个三位的整数,该函数将 num的百位、十位和个位的数字进行重排,并返回由上述的三个数字组成的最大的三位数。 注意:部分源程序已存在文件 test28_2.cpp中。 如输入 456后,输出结果如下: 654 请勿修改主函数 main和其他函数中的任何内容,仅在函数 sortnum的花括号中填写若干语句。 文件 test28_2.cpp的内容如下: #include iostream.h int sortnum(in

3、t num) void main() int num; int result=0; cout “请输入一个三位数 ”; cin num; cout sortnum(num) end1; 三、综合应用题( 30分) 2 使用 VC6打开考生文件夹下的工程 MyProj15。此工程包含一个源程序文件MyMain15.cpp。程序中定义了 3个类 A、 B和 C,但类的定义并不完整。 请按要求完成下列操作,将类的定义补充完成: 类 Inherit是类 Base的公有派生类。请在注释 “/* *1* *”之后添加适当的语句。 完 成类 Inherit成员函数 setvalue(int a,int b,

4、int c,int d)的定义,此函数实现的功能是将基类成员 x、 y、 z 和派生类的数据成员 m的值分别设置成 a、 b、 c和 d。请在注释 “/* *2* *”之后添加适当的语句。 完成类 Inherit成员函数 display()的类体外定义,此函数实现的功能是以 “,”的格式将 x、 y、 z和 m的值输出到屏幕上。请在注释 “/* *3* *”之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件 MyMain15.cpp清单如下: /Mymain15.cpp #include iostream using namespace std; c

5、lass Base private: int x; protected: int y; public: int z; void setx(int i) x=i; int getx()const return x; ; /* * *1* * * private: int m; public: void setvalue(int a, int b, int c, int d) /* * *2* * * void display()const; ; /* * *3* * * int main() Inherit A; A setvalue(1, 2, 3, 4); A display(); retu

6、rn 0; 国家二级( C+)机试模拟试卷 58答案与解析 一、程序改错题( 30分) 1 【正确答案】 (1) 错误: static int n=1; 正确: static int n; (2) 错误: int n=0; 正确: int A: n=0; (3) 错误: cout c.n end1; 正确 : cout c- n end1; 【试题解析】 (1)在类的声明中只能对静态数据成员进行引用性声明,不能进行静态数据成员的初始化: (2)由于静态数据成员是类的成员,所以在初始化时必须限定它所属的类: (3)c为类的对象指针,访问类成员函数时使用符号 “- ”,而不能用 “ ”。 二、简单

7、应用题( 40分) 2 【正确答案】 int sortnum(int num) int number 3 , i, j, temp; for (i=0; i 3; i+) number i =num%10; num=num/10; for (i=0;i 2 ;i+) for (j=i+1; j 3;j+) if (numberj =numberi) temp=number j; number j =number i; number i =temp; num=number 2 *100+number 1*10+number0; return num; 【试题解析】 本题除考查考生对基本控制结构和数组访问的熟练程度外,还考查了考生根据实际需要,建立模型,对数字进行排序的能力,答案中所示时是冒泡排序法。请注意程序中数组下标的范围和两层 for循环嵌套中循环变量的取值情况。 三、综合应用题( 30分)

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 2515-1989 Aerospace Series Rod Ends Adjustable Single Fork and Threaded Shank Dimensions and Loads《航空航天系列.可调整单叉 尺寸和负荷》.pdf AECMA PREN 2515-1989 Aerospace Series Rod Ends Adjustable Single Fork and Threaded Shank Dimensions and Loads《航空航天系列.可调整单叉 尺寸和负荷》.pdf
  • AECMA PREN 2516-1996 Aerospace Series Passivation of Corrosion Resistant Steels and Decontamination of Nickel Base Alloys Edition 1《航空航天系列.防腐钝化钢和镍基净化合金1板》.pdf AECMA PREN 2516-1996 Aerospace Series Passivation of Corrosion Resistant Steels and Decontamination of Nickel Base Alloys Edition 1《航空航天系列.防腐钝化钢和镍基净化合金1板》.pdf
  • AECMA PREN 2517-1983 Titanium Alloy TI-P63 Annealed Sheets Strips and Plates A Less Than or Equal to 100 mm Aerospace Series Edition 1《航空航天系列.TI-P63钛合金退火片 带和板材A小于或等于100mm.第1版》.pdf AECMA PREN 2517-1983 Titanium Alloy TI-P63 Annealed Sheets Strips and Plates A Less Than or Equal to 100 mm Aerospace Series Edition 1《航空航天系列.TI-P63钛合金退火片 带和板材A小于或等于100mm.第1版》.pdf
  • AECMA PREN 2518-1982 Titanium TI-P02 390 MPa Less Than or Equal to Rm Less Than or Equal to 540 MPa Bars De Less Than or Equal to 200 mm Aerospace Series Edition 1《航空航天系列钛棒材 TI-P02.pdf AECMA PREN 2518-1982 Titanium TI-P02 390 MPa Less Than or Equal to Rm Less Than or Equal to 540 MPa Bars De Less Than or Equal to 200 mm Aerospace Series Edition 1《航空航天系列钛棒材 TI-P02.pdf
  • AECMA PREN 2519-1994 Titanium TI-P04 540 MPa Less Than or Equal to Rm Less Than or Equal to 740 MPa Bars De Less Than or Equal to 200 mm Aerospace Series Edition 2 [Refer To ASD-ST.pdf AECMA PREN 2519-1994 Titanium TI-P04 540 MPa Less Than or Equal to Rm Less Than or Equal to 740 MPa Bars De Less Than or Equal to 200 mm Aerospace Series Edition 2 [Refer To ASD-ST.pdf
  • AECMA PREN 2520-1982 Titanium TI-P04 540 MPa Less Than or Equal to Rm Less Than or Equal to 740 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series Edition 1《航空航天系列钛锻件 TI.pdf AECMA PREN 2520-1982 Titanium TI-P04 540 MPa Less Than or Equal to Rm Less Than or Equal to 740 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series Edition 1《航空航天系列钛锻件 TI.pdf
  • AECMA PREN 2521-1994 Titanium Alloy TI-P11 540 MPa Less Than or Equal to Rm Less Than or Equal to 700 MPa Bars De Less Than or Equal to 200 mm Aerospace Series Edition 2 [Refer To .pdf AECMA PREN 2521-1994 Titanium Alloy TI-P11 540 MPa Less Than or Equal to Rm Less Than or Equal to 700 MPa Bars De Less Than or Equal to 200 mm Aerospace Series Edition 2 [Refer To .pdf
  • AECMA PREN 2522-1982 Titanium Alloy TI-P11 540 MPa Less Than or Equal to Rm - Less Than or Equal to 700 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series Edition 1《航空航天.pdf AECMA PREN 2522-1982 Titanium Alloy TI-P11 540 MPa Less Than or Equal to Rm - Less Than or Equal to 700 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series Edition 1《航空航天.pdf
  • AECMA PREN 2523-1982 Titanium alloy TI-P11 650 MPa Less Than or Equal to Rm Less Than or Equal to 880 MPa Bars De Less Than or Equal to 75 mm Aerospace Series Edition 1《航空航天系列钛合金棒材.pdf AECMA PREN 2523-1982 Titanium alloy TI-P11 650 MPa Less Than or Equal to Rm Less Than or Equal to 880 MPa Bars De Less Than or Equal to 75 mm Aerospace Series Edition 1《航空航天系列钛合金棒材.pdf
  • 相关搜索

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

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