【计算机类职业资格】二级C++机试-34及答案解析.doc

上传人:ideacase155 文档编号:1324375 上传时间:2019-10-17 格式:DOC 页数:7 大小:31.50KB
下载 相关 举报
【计算机类职业资格】二级C++机试-34及答案解析.doc_第1页
第1页 / 共7页
【计算机类职业资格】二级C++机试-34及答案解析.doc_第2页
第2页 / 共7页
【计算机类职业资格】二级C++机试-34及答案解析.doc_第3页
第3页 / 共7页
【计算机类职业资格】二级C++机试-34及答案解析.doc_第4页
第4页 / 共7页
【计算机类职业资格】二级C++机试-34及答案解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、二级 C+机试-34 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 RevProj14。此工程包含一个源程序文件 RevMain14.cpp,但该程序中类的定义有错误。请改正程序中的错误,使它能得到正确结果。注意,不要改动 main 函数,不得删行或增行,也不得更改程序的结构。源程序文件 RevMain14.cpp 中的程序清单如下:/RevMain14.cpp#includeiostream#includemathusing namespace std;class Pointprivate:doub

2、le x;double y;public:Point()void Point(double x1,double y1)x=x1;y=y1;void setvalue(double x,double y)x=x;y=y;double getx ()return x;double gety()return y;void print()cout“x=“x“,y= “yend1;Point();class Lineprivate:Point p1;Point p2;double width;public:Line(double x1,double y1,double x2,double y2,doub

3、le d):p1(x1,y1),p2(x2,y2)width=d;Line()void displength()double 1;1=sqrt(p1.getx)-p2.getx()*(p1.getx()-p2-getx()+(p1.gety()-p2.gety()*(p1.gety()-p2.gety();cout“the length of Line is “1end1;int main()Line *p1;Line 1(5,15,25,35,0.5);p1=p1-displength();return 0;(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.请编写一个

4、函数 fun(),它的功能是求出一个正整数的所有因子。例如,若输入 72, 则程序应该输出:72=2*2*2*3*3。注意:部分源程序已存在文件 PROC14。CPP 中。请勿修改主函数和其他函数中的任何内容,仅在函数 fun()的花括号中填写若干语句。文件 PROC14.cpp 的内容如下:/PROC14. cpp#include iostreamusing namespace std;void fun(int number);int main ( )int n;cout“Please enter a number /n“;cinn;coutn“=“;fun (n);return 0;voi

5、d fun(int number)/* * * * * * *(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.return 0;(分数:34.00)_二级 C+机试-34 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 RevProj14。此工程包含一个源程序文件 RevMain14.cpp,但该程序中类的定义有错误。请改正程序中的错误,使它能得到正确结果。注意,不要改动 main 函数,不得删行或增行,也不得更改程序的结构。源程序文件 RevMain14.cpp 中的程序清单如

6、下:/RevMain14.cpp#includeiostream#includemathusing namespace std;class Pointprivate:double x;double y;public:Point()void Point(double x1,double y1)x=x1;y=y1;void setvalue(double x,double y)x=x;y=y;double getx ()return x;double gety()return y;void print()cout“x=“x“,y= “yend1;Point();class Lineprivate:

7、Point p1;Point p2;double width;public:Line(double x1,double y1,double x2,double y2,double d):p1(x1,y1),p2(x2,y2)width=d;Line()void displength()double 1;1=sqrt(p1.getx)-p2.getx()*(p1.getx()-p2-getx()+(p1.gety()-p2.gety()*(p1.gety()-p2.gety();cout“the length of Line is “1end1;int main()Line *p1;Line 1

8、5,15,25,35,0.5);p1=p1-displength();return 0;(分数:33.00)_正确答案:(正确的类 Point 的定义如下;class Pointprivate:double x,y;public:Point () Point (double x1, double y1)x=x1;y=y1;void setvalue(double x, double y)this-x=x; / Point:x=x;this-y=y; /Point:y=y;double getx() return x; double gety() return y; void print ()

9、cout“x= “x“,y= “yend1;Point() ;)解析:解析 程序中有两处错误。都是在类 Point 的定义中。C+中类的构造函数没有函数返回类型。所以类 Point 的重载构造函数首部前不应该有 void 说明。在成员函数 setvalue()中,变量 x 和 y 指示不明确,会产生二义性。所以应该使用 this 指针或作用域分辨符指明。二、2简单应用题(总题数:1,分数:33.00)2.请编写一个函数 fun(),它的功能是求出一个正整数的所有因子。例如,若输入 72, 则程序应该输出:72=2*2*2*3*3。注意:部分源程序已存在文件 PROC14。CPP 中。请勿修改主

10、函数和其他函数中的任何内容,仅在函数 fun()的花括号中填写若干语句。文件 PROC14.cpp 的内容如下:/PROC14. cpp#include iostreamusing namespace std;void fun(int number);int main ( )int n;cout“Please enter a number /n“;cinn;coutn“=“;fun (n);return 0;void fun(int number)/* * * * * * *(分数:33.00)_正确答案:(函数 fun()的定义如下:void fun(int number)int i,fac

11、tor;for(i=2;i=number;i+)if(number%i=0)factor=i;break;coutfactorz“*“;if(number!=i)number=number/i;fun(number);elsefor(i=0;i2;i+)cout/b;cout“ “;)解析:解析 实现此函数的方法有很多种,上述实现方式是采用了函数的递推调用。三、3综合应用题(总题数:1,分数:34.00)3.return 0;(分数:34.00)_正确答案:(virtual void setx(int i,int j=0)x=i;y=j;virtual void print=0;int x,y;)解析:解析 该程序中定义了 A 类、B 类和 C 类共 3 个类。其中,类 A 是抽象类,它的类体内有一个纯虚函数 print()。抽象类不可以定义对象,但可以定义指向对象的指针。类 B 和类 C 都是类 A 的公有派生类,这些类是具体类,它们对 A 类中纯虚函数都有不同的实现。该程序的主函数中,定义一个指向类 A 对象的指针 pa,又定义了类 B 和类 C 的 2 个对象,并使指针 pa 分别指向这些对象。这里,采用动态联编,在运行时选择 print()函数。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索
    资源标签

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

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