【计算机类职业资格】二级C++机试-77及答案解析.doc
《【计算机类职业资格】二级C++机试-77及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级C++机试-77及答案解析.doc(7页珍藏版)》请在麦多课文档分享上搜索。
1、二级 C+机试-77 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:30.00)1.使用 VC6 打开考生文件夹下的工程 test42_1,此工程包含一个源程序文件 test42_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:rect area: 12rectb area: 30源程序文件 test42_1.cpp 清单如下:#include iostream.hclass CRectangle/* found */int *width, height;public:CRectangle (int,int);CRectangl
2、e ();int area (void) return (*width * *height);CRectangle:CRectangle (int a, int b)width = new int;height = new int;/* found */width = a;*height = b;CRectangle:CRectangle ()delete width;delete height;/* found */void main ()CRectangle rect (3,4), rectb (5,6);cout “rect area: “ rect.area() endl;cout “
3、rectb area: “ rectb.area() endl;return 0;(分数:30.00)填空项 1:_二、2简单应用题(总题数:1,分数:40.00)2.请编写一个函数 maxofarray(atype*p,int count),该函数从一个数组中找出其中的最大元素,并且数组中可以存放多种数据类型的元素。注意:部分源程序己存在文件 test42_2.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 maxofarray 的花括号中填写若干语句。文件 test42_2.cpp 清单如下:#includeiostream.h#includestring.h#in
4、cludeconio.htemplateclass atypevoid maxofarray(atype* p,int count)void main ()int len=5;char *p1;cout“the char type array and its length is 5:/n“;cout“the array element is a b c d e/n“;p1=new charlen;for (int i=0;ilen;i+)p1i=a+i;maxofarray(p1,len);(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.使用 VC6 打开考生文件夹下
5、的工程 test42_3。此工程包含个 test42_3.cpp,其中定义了类Cpolygon、COutput 和 CTriangle,其中 CTriangle 类由 Cpolygon 和 COutput 类 public 派生,但三个类的定义并不完整。请按要求完成下列操作,将程序补充完整。(1)定义类 CPolygon 的保护数据成员 width 和 height,它们都是 int 型的数据。请在注释“/*1*”之后添加适当的语句。(2)完成类 CPolygon 的成员函数 set_values(int a,int b),使参数 a 和 b 分别赋值给保护数据成员width 和 height
6、,请在注释“/*2*”之后添加适当的语句。(3)完成类 Coutput 的成员函数 output(int)的定义,将传入的参数为血型的 i 输出到屏幕并换行,请在注释“/*3*”之后添加适当的语句。(4)完成派生类 CTriangle 的声明,它由 Cpolygon 和 COutput 类 public 派生,请在注释“/*4*”之后添加适当的语句。源程序文件 test42_3.cpp 清单如下:#include iostream.hclass CPolygonprotected:/ * 1 *public:void set_values(int a, int b)/ * 2 *;class
7、COutputpublic:void output(int i);void COutput:output(int i)/ * 3 */ * 4 *public:int area (void)return (width * height / 2);int main ()CTriangle trgl;trgl.set_values (4,5);trgl.output (trgl.area();return 0;(分数:30.00)_二级 C+机试-77 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:30.00)1.使用 VC6 打开考生文件夹下的工程 test
8、42_1,此工程包含一个源程序文件 test42_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:rect area: 12rectb area: 30源程序文件 test42_1.cpp 清单如下:#include iostream.hclass CRectangle/* found */int *width, height;public:CRectangle (int,int);CRectangle ();int area (void) return (*width * *height);CRectangle:CRectangle (int a, int b)wi
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 机试 77 答案 解析 DOC
