【计算机类职业资格】二级C++机试-88及答案解析.doc
《【计算机类职业资格】二级C++机试-88及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++机试-88及答案解析.doc(9页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+机试-88 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test12_1,此工程包含一个源程序文件 test_12.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:fun (Sample &p) 1 2fun (Sample *p) 3 420 10源程序文件 test12_1 清单如下:#includeiostream .hclass Sampleprivate:int x,y;static int z;public:Sample(int a,int b) x=a
2、;y=b; void fun(Sample &p);void fun(Sample *p);static void print(Sample s);/* found */int z=10;void Sample:fun(Sample &p)x=p.x;y=p.y;cout“fun(Sample &p)“ “x“ “yendl;void Sample:fun(Sample *p)/* found */x=p.x; y=p.y;cout“fun(Sample *p) “ x“ “yendl;void Sample:print (Sample s)/* found */x=20;couts. x“
3、“zendl;void main()Sample p(1,2),q(3,4);p. fun(p);p. fun(&q);p. print(p);(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.请编写一个函数 int Count(double a,int n),统计出具有 n 个元素的一维数组中大于等于所有元素平均值的元素个数并返回这个值。注意:请使用 for 循环实现该函数。注意:部分源程序已存在文件 test12_2.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 Count 的花括号中填写若干语句。文件 test12_2 的内容如下:#in
4、cludeiostream.hint Count(double a, int n)void main()double a5;cout“请输入 5 个 double 型的数字“endl;for(int i=0;i5;i+)cinai;int result=Count(a,5);cout“大于等于所有元素平均值的元素个数:“resultendl;(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.使用 VC6 打开考生文件夹下的工程 test12_3,此工程包含一个 test12_3.cpp,其中定义了类 Base 和类A,类 A 公有继承 Base,但这两个类的定义都并不完
5、整。请按要求完成下列操作,将程序补充完整。(1)定义枚举类型变量 en,它包含两个枚举符 front 和 back,请在注释“/*1*”之后添加适当的语句。(2)在类 Base 中添加常成员虚函数 void E()的定义,该函数输出“In Base E!”,请在注释“/*2*”之后添加适当的语句。(3)在类 A 中添加常成员虚函数 void E()的定义,该函数先调用基类中的虚函数 E()再输出“In AE!”,请在注释“/* 3*”之后添加适当的语句。(4)完成类 A 构造函数的定义,请使用参数列表的形式初始化类 A 的成员,并输出“A constructor.”,请在注释“/* 4*”之后
6、添加适当的语句。输出结果如下:Base constructor.A constructor.In BaseE!In AE!In BaseP!In A!1A destructor.Base destructor.注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。源程序文件 test12_3.cpp 清单如下:#includeiostream .h/ * 1 *class Baseprotected:int b1;int b2;public:Base();Base();int Getb1()const return b1; void Setb1(int x) b1 = x; int Ge
7、tb2()const return b2; void Setb2(int y) b2 = y; void Print()const cout“In Base P!“end1;/ * 2 *;Base:Base():b1(1),b2(5)cout“Base constructor“endl;Base:Base()cout“Base destructor.“endl;class A:public Baseprotected:en enA;public:A();A();en GetColor()const return enA; void SetColor(en color) enA = color
8、; void InA()cout“In A!“endl;/ * 3 *Base:E();cout“In AE!“endl;/ * 4 *cout“A constructor.“endl;A:A()cout“A destructor.“endl;void main()A a1;a1.E();coutendl;a1.Print();a1InA();couta1.Getbl()endl;(分数:34.00)_二级 C+机试-88 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test12_1,此工程包含一个源
9、程序文件 test_12.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:fun (Sample &p) 1 2fun (Sample *p) 3 420 10源程序文件 test12_1 清单如下:#includeiostream .hclass Sampleprivate:int x,y;static int z;public:Sample(int a,int b) x=a;y=b; void fun(Sample &p);void fun(Sample *p);static void print(Sample s);/* found */int z=10;void
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 机试 88 答案 解析 DOC
