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

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

1、国家二级( C+)机试模拟试卷 52及答案与解析 一、程序改错题( 30分) 1 使用 VC6打开考生文件夹下的工程 test38_1,此工程包含一个源程序文件test38_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为: 2 is a factor of 10 源程序文件 test38_1.cpp清单如下: #include iostream.h class myclass /* found */ int n,d public: myclass(int i, int j) n=i; d=j; friend int factor( myclass ob); ; /*

2、found */ int myclass:factor(myclass ob) /* found */ if(ob.n%ob.d) return 1; else return 0; void main() myclass ob1(10,2),ob2(13,3); if(factor(ob1) cout “2 is a factor of 10n“; if(factor(ob2) cout “3 is not a factor of 13n“; 二、简单应用题( 40分) 2 请编写函数 fun(),该函数的功能是将 M行 N列的二维数组中的数据,按列的顺序依次放到一维数组中。 例如:二维数组中

3、的数据为 33333333 44444444 55555555 则一维数组中的内容应是 334455334455334455334455。 注意:部分源程序以存在文件 test_2.cpp中。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。 文件 test39_2.cpp的内容如下: #include stdio.h #include iostream.h void fun(int(*s) 10,int *b, int *n,int mm,int nn) void main( ) int w1010=33,33,33,33,44,44,44,4

4、4,55,55,55,55,i,j; int a100=0, n=0; cout “The matrix:n“ for(i=0; i 3; i+) for(j=0; j 4; j+ cout wi j; cout endl; fun(w, a, cout “The A array:n“; for(i=0; i n; i+) cout ai; cout “nn“; 三、综合应用题( 30分) 3 使用 VC6打开考生文件夹下的工程 test37_3。此工程包含一个 test37_3.cpp,其中定义了类 Letter和 Number以及 Grid,其中 Grid类由 Letter类和 Numbe

5、r类public派生,但三个类的定义并不完整。请按要求完成下列操作,将程序补充完整。 (1)添加类 Letter的带一个参数 c的构造函数, c是 char型的数据,默认值为 A,该函数把参数 c的值赋给类的保护成员 ch,请在注释 “/*1*”之后添加适当的语句。 (2)添加类 Number的带一个参数 n的构造函数, n是 int型的数据,默认值为 0,该函数把参数 n的值赋给类的保护成员 num,请在注释 “/*2*”之后添加适当的语句。 (3)添加派生类 Grid构造函数的定义,传入的参数为 char型的 c和血型的 n,并将其分别赋值给基类的 ch和 num,请在注释 “/*3*”之

6、后添加适当的语句。 (4)完成派生类 Grid的友元函数 “ ”运算符重载的定义,使其以格式“g.ch, g.num”输出,请在注释 “/*4 *”之后添加适当的语句。 源程序文件 test37_3.cpp清单如下: #include iost ream. h class Letter protected: char ch; public: / * 1 * ; class Number protected: int num; public: / * 2 * ; class Grid : public Letter, public Number public: / * 3 * friend os

7、tream ; / * 4 * o “ g.ch “, “ g.num “; return o; int main ( ) Grid g(C, 3); cout “Grid reference: “ g end1; return 0; 国家二级( C+)机试模拟试卷 52答案与解析 一、程序改错题( 30分) 1 【正确答案】 (1) 错误: int n, d 正确; int n, d; (2) 错误: int myclass:factor(myclass ob) 正确: int factor(myclass ob) (3) 错误: if(ob.n%ob.d) 正确: if(ob.n%ob.d

8、) 【试题解析】 (1)主要考查考生对于变量定义的理解,同类型的变量定义中间使用逗号分开,同时可以进行初始化,但是在整个定义的结尾必须使用分号,这是C+的规定: (2)主要考查考生是否掌握了友元函数的定义,友元是在类的内部声明,类的外部实现的一种特殊的函数,它可以访问类内的所有成员,不过在类外的实现和调用的时候均不需要使用作用域符号 “:”限制: (3)主要考查考生对于 if条件语句的掌握,只有括号内的条件为真,即值为 1时,才执行 if后面的语句,根据题目要求应该执行的是对象 ob1,即 2可以整除 10,所以应该定义函数 factor的返回值为能整除返回 1,否则为 0,而能够整除即取余运

9、算值为 0,所以在判断前应该加上非运算。 二、简单应用题( 40分) 2 【正确答案】 void fun (int(*s)10,int *b, int *n, int mm, int nn) int i,j; for(j=0;j nn;j+) for(i=0;i mm;i+) b*n=*(*(s+i)+j);*n=*n+1; 【试题解析】 一个二维数组的存储可以理解为按行进 行存储的 个 维数组,但本题中的二维数组要求按列进行存储。根据在主函数中的调用情况,可以看出,指针数组 s10实质上是用来存放二维数组中各行的首地址, b是用来存放最终二维数组按列处理完毕后的一个一维数组,第 3个参数之所

10、以要用 “&n”,目的是为了能在函数中直接改变其值。 三、综合应用题( 30分) 3 【正确答案】 (1) Letter(char c A)ch c; (2) Number(int n 0)num n; (3) Grid(char c A, int n 0): Letter(c), Number(n) (4) ostream &operator (ostream &o,Grid &g) 【试题解析】 主要考查考生对于类和派生类的构造函数的定义以及重载为友元的运算符函 -数的定义的掌握,其中 (3)使用了参数列表进行变量赋值,这是派生类构造函数中经常使用的, (4)对于友元函数在类体外的定义不需要使用作用域符,而ostream类的对象引用可直接使用原来意义的符号 “ ”进行输出。

展开阅读全文
相关资源
猜你喜欢
  • STAS SR ISO 7884-2-1996 Glass - Viscosity and viscometric fixed points Part 2 Determination of viscosity by rotation viscometers《玻璃 粘度和粘度固定点 第2部分:用转动粘度计测定粘度 》.pdf STAS SR ISO 7884-2-1996 Glass - Viscosity and viscometric fixed points Part 2 Determination of viscosity by rotation viscometers《玻璃 粘度和粘度固定点 第2部分:用转动粘度计测定粘度 》.pdf
  • STAS SR ISO 7884-3-1996 Glass - Viscosity and viscometric fixed points - Part 3 Determination of viscosity by fibre elongation viscometer《玻璃 粘度和粘度固定点 第3部分:纤维伸长粘度计测定粘度 》.pdf STAS SR ISO 7884-3-1996 Glass - Viscosity and viscometric fixed points - Part 3 Determination of viscosity by fibre elongation viscometer《玻璃 粘度和粘度固定点 第3部分:纤维伸长粘度计测定粘度 》.pdf
  • STAS SR ISO 7884-5-1995 Glass - Viscosity and viscometric fixed points - Part 5 Determination of working point by sinking bar viscometer《玻璃 粘度和粘度固定点 第5部分:用浸没杆式粘度计测定工作点 》.pdf STAS SR ISO 7884-5-1995 Glass - Viscosity and viscometric fixed points - Part 5 Determination of working point by sinking bar viscometer《玻璃 粘度和粘度固定点 第5部分:用浸没杆式粘度计测定工作点 》.pdf
  • STAS SR ISO 7930-1995 Wheelchairs - Type classification based on appearance characteristics《轮椅 外观特征基础上的类型分类 》.pdf STAS SR ISO 7930-1995 Wheelchairs - Type classification based on appearance characteristics《轮椅 外观特征基础上的类型分类 》.pdf
  • STAS SR ISO 7931-1993 Insulation caps and bushes for resistance welding equipment《电阻焊设备的绝缘帽和套筒 》.pdf STAS SR ISO 7931-1993 Insulation caps and bushes for resistance welding equipment《电阻焊设备的绝缘帽和套筒 》.pdf
  • STAS SR ISO 7965-2-1996 Sacks Drop test - Part 2 Sacks made from thermoplastic flexible film《袋坠落试验 第2部分:热塑性软簿膜制成的包装袋 》.pdf STAS SR ISO 7965-2-1996 Sacks Drop test - Part 2 Sacks made from thermoplastic flexible film《袋坠落试验 第2部分:热塑性软簿膜制成的包装袋 》.pdf
  • STAS SR ISO 7984-1996 Woodworking machines - Tehnical classification of woodworking machines and auxiliary machines for woodworking《木工机械 木工机械和辅助机械分类 》.pdf STAS SR ISO 7984-1996 Woodworking machines - Tehnical classification of woodworking machines and auxiliary machines for woodworking《木工机械 木工机械和辅助机械分类 》.pdf
  • STAS SR ISO 7990-1996 Manganese ores and concentrates — Determination of total iron content - Titrirnetiic method after reriuction and sulfosalicylic acid spectrofotometric rnpthod.pdf STAS SR ISO 7990-1996 Manganese ores and concentrates — Determination of total iron content - Titrirnetiic method after reriuction and sulfosalicylic acid spectrofotometric rnpthod.pdf
  • STAS SR ISO 8002-1994 Mechanical vibrations - Land vehicles - Method for reporting measured data《机械振动 地面车辆 报告测量数据的方法 》.pdf STAS SR ISO 8002-1994 Mechanical vibrations - Land vehicles - Method for reporting measured data《机械振动 地面车辆 报告测量数据的方法 》.pdf
  • 相关搜索

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

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