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

上传人:appealoxygen216 文档编号:1324383 上传时间:2019-10-17 格式:DOC 页数:6 大小:33.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 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test11_1,此工程包含一个源程序文件 test11_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:ch1=7 ch2=9源程序文件 test11_1.cpp 清单如下:#includeiostream.hclass Sample/* found */char ch1,ch2public:/* found */friend void set(Sample s, char c1,char c2)sch1=

2、c1;sch2=c2;void print() cout“ch1=“ ch2=“ch2end1;void main()Sample obj;/* found */obj.set(obj,7,9);obj.print();(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.请编写一个函数 int sum(int n),该函数完成 1+2+3+n 的运算,并返回运算结果,其中 n0。注意:请使用递归算法实现该函数。注意:部分源程序已存在文件:test11.cpp 中。请勿修改主函数 main 和其他函数中的任何内容,仅在函数 sum 的花括号中填写若干语句。文件 test11

3、_2.cpp 的内容如下:#includeiostream.hint sum(int n)void main()int n;cout“输入 n:“;cinn;int result;sum(n);cout“结果为:“resultendl;(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.使用 VC6 打开考生文件夹下的工程 test11_3。此工程包含一个 test11_3.cpp,其中定义了类CPosition,但该类的定义都并不完整。请按要求完成下列操作,将类 CPosition 的定义补充完整。(1)在类定义外完成重载的两个构造函数 CPosition()和 CPo

4、sition(double dx,double dy),其中前者为不带参数的构造函数,使 CPosition 对象的默认值为 x=0,y=0,后者为带参数的构造函数,把数据成员x 和 y 分别初始化为参数 dx 和 dy 的值。请在注释“/*1*”之后添加适当的语句。(2)在类体中添加函数 move(double ax,double ay)的定义,使得点的坐标 x 和 y 分别移动 ax 和 ay 个单位,请在注释“/ *2*”之后添加适当的语句。(3)完成函数 double distance (double bx,double by)的定义,该函数返回*this 和点(bx,by)的距离,请

5、在注释“/*3*”之后添加适当的语句。注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。源程序文件 test11_3.cpp 清单如下:#includeiostream.h#includemath.hclass CPositionpublic:CPosition();CPosition(double dx,double dy);double getx();double gety();/ * 2 *double distance(double bx,double by);private:double x;double y;/ * 1 *x=0;y=0;CPosition:CPositi

6、on(double dx,double dy)x=dx;y=dy;double CPosition:getx()return x;double CPosition:gety()return y;double CPosition:distance(double bx,double by)/ * 3 *void main()double a,b;cout “Input x, y position of a point:“;cin a b;CPosition psA(a,b);cout “Input x,y position of another point:“;cin a b;cout “The

7、distance is “ psAdistance(a,b) endl;(分数:34.00)_二级 C+机试-52 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test11_1,此工程包含一个源程序文件 test11_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:ch1=7 ch2=9源程序文件 test11_1.cpp 清单如下:#includeiostream.hclass Sample/* found */char ch1,ch2public:/* found */f

8、riend void set(Sample s, char c1,char c2)sch1=c1;sch2=c2;void print() cout“ch1=“ ch2=“ch2end1;void main()Sample obj;/* found */obj.set(obj,7,9);obj.print();(分数:33.00)_正确答案:(1)错误:char ch1,ch2正确:char ch1,ch2;(2)错误:friend void set(Samples,char c1,char c2)正确:friend void set(Sample y+=ay;(3)return sqrt(pow(x-bx,2)+pow (y-by,2);)解析:解析本题主要考查考生对于类的定义和重载构造函数的掌握情况。在(3)中使用了基本的数学函数 sqrt(x)求 x 的开方,pow (x, n)函数是求 x 的 n 次方。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN ISO 6721-3-1996 Plastics - Determination of dynamic mechanical properties - Part 3 Flexural vibration resonance-curve (ISO 6721-3 1994 including Technical Corrigendum 1 1995.pdf DIN EN ISO 6721-3-1996 Plastics - Determination of dynamic mechanical properties - Part 3 Flexural vibration resonance-curve (ISO 6721-3 1994 including Technical Corrigendum 1 1995.pdf
  • DIN EN ISO 6743-4-2015 Lubricants industrial oils and related products (class L) - Classification - Part 4 Family H (Hydraulic systems) (ISO 6743-4 2015) German version EN ISO 6743.pdf DIN EN ISO 6743-4-2015 Lubricants industrial oils and related products (class L) - Classification - Part 4 Family H (Hydraulic systems) (ISO 6743-4 2015) German version EN ISO 6743.pdf
  • DIN EN ISO 6744-1-2004 Binders for paints and varnishes - Alkyd resins - Part 1 General methods of test (ISO 6744-1 1999) German version EN ISO 6744-1 2004《色漆和清漆用粘合剂 醇酸树脂 第1部分 通用试验.pdf DIN EN ISO 6744-1-2004 Binders for paints and varnishes - Alkyd resins - Part 1 General methods of test (ISO 6744-1 1999) German version EN ISO 6744-1 2004《色漆和清漆用粘合剂 醇酸树脂 第1部分 通用试验.pdf
  • DIN EN ISO 6744-2-2004 Binders for paints and varnishes - Alkyd resins - Part 2 Determination of phthalic anhydride content (ISO 6744-2 1999) German version EN ISO 6744-2 2004《色漆和清.pdf DIN EN ISO 6744-2-2004 Binders for paints and varnishes - Alkyd resins - Part 2 Determination of phthalic anhydride content (ISO 6744-2 1999) German version EN ISO 6744-2 2004《色漆和清.pdf
  • DIN EN ISO 6744-3-2004 Binders for paints and varnishes - Alkyd resins - Part 3 Determination of unsaponifiable matter content (ISO 6744-3 1999) German version EN ISO 6744-3 2004《色.pdf DIN EN ISO 6744-3-2004 Binders for paints and varnishes - Alkyd resins - Part 3 Determination of unsaponifiable matter content (ISO 6744-3 1999) German version EN ISO 6744-3 2004《色.pdf
  • DIN EN ISO 6744-4-2004 Binders for paints and varnishes - Alkyd resins - Part 4 Determination of fatty acid content (ISO 6744-4 1999) German version EN ISO 6744-4 2004《色漆和清漆用粘合剂 醇酸.pdf DIN EN ISO 6744-4-2004 Binders for paints and varnishes - Alkyd resins - Part 4 Determination of fatty acid content (ISO 6744-4 1999) German version EN ISO 6744-4 2004《色漆和清漆用粘合剂 醇酸.pdf
  • DIN EN ISO 676-2009 Spices and condiments - Botanical nomenclature (ISO 676 1995 including Cor 1 1997) Trilingual version EN ISO 676 2009《香料和调味品 植物命名(ISO 676 1995 含勘误表1 1997) 三种语言版.pdf DIN EN ISO 676-2009 Spices and condiments - Botanical nomenclature (ISO 676 1995 including Cor 1 1997) Trilingual version EN ISO 676 2009《香料和调味品 植物命名(ISO 676 1995 含勘误表1 1997) 三种语言版.pdf
  • DIN EN ISO 6781-3-2016 Performance of buildings - Detection of heat air and moisture irregularities in buildings by infrared methods - Part 3 Qualifications of equipment operators .pdf DIN EN ISO 6781-3-2016 Performance of buildings - Detection of heat air and moisture irregularities in buildings by infrared methods - Part 3 Qualifications of equipment operators .pdf
  • DIN EN ISO 6789-1-2017 Assembly tools for screws and nuts - Hand torque tools - Part 1 Requirements and methods for design conformance testing and quality conformance testing minim.pdf DIN EN ISO 6789-1-2017 Assembly tools for screws and nuts - Hand torque tools - Part 1 Requirements and methods for design conformance testing and quality conformance testing minim.pdf
  • 相关搜索
    资源标签

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

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