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

上传人:outsidejudge265 文档编号:1324405 上传时间:2019-10-17 格式:DOC 页数:4 大小:39.50KB
下载 相关 举报
【计算机类职业资格】二级C++机试18及答案解析.doc_第1页
第1页 / 共4页
【计算机类职业资格】二级C++机试18及答案解析.doc_第2页
第2页 / 共4页
【计算机类职业资格】二级C++机试18及答案解析.doc_第3页
第3页 / 共4页
【计算机类职业资格】二级C++机试18及答案解析.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 C+机试 18及答案解析(总分:100.00,做题时间:90 分钟)一、B1改错题/B(总题数:1,分数:30.00)1.使用 VC6打开考生文件夹下的工程 test21_1,此工程包含一个源程序文件 test21_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下: The grade is 3 源程序文件 test21_1.cpp清单如下: #includeiostream.h class student private: int grade; public: /* found*/ student(int thegra):(thegra) student() i

2、nt get_grade()return grade; ; void main() int thegra=3; /* found*/ student point=new student(thegra); /* found*/ cout“The grade is“point.get_grade()endl; delete point; (分数:30.00)二、B2简单应用题/B(总题数:1,分数:40.00)2.请编写一个函数 char*change(char instr),将输入字符串中的所有小写字母转换为大写字母输出。要求使用 for循环实现。如输入 jinfeiteng,则输出结果是 JI

3、NFEITENG。 注意:部分源程序已存在文件test21_2.cpp中。 请勿修改主函数 main和其他函数中的任何内容,仅在函数 change的花括号中填写若干语句。 文件 test21_2.cpp的内容如下: char*change(char instr); #include“iostream.h“ void main() char instr50; char *outstr; cout“Input a string:“endl; cininstr; outstr=change(instr); cout“Over graded string:“endl; coutoutstrendl;

4、char*change(char instr) (分数:40.00)_三、B3综合应用题/B(总题数:1,分数:30.00)3.使用 VC6打开考生文件夹下的工程 test21_3,此工程包含一个源程序文件 test21_3.cpp,其中定义了用于表示长方形的类 CRectangle,但类 CRectangle的定义并不完整。请按要求完成下列操作,将类CRectangle的定义补充完整。 (1)定义 CRectangle的构造函数,函数含参数 dx,dy,da 和 db,它们都是 double型的数据,请将类数据成员 x,y, a 和 b初始化,并输出“CRectangle Construct

5、ed.”(另起一行输出该文字)。请在注释“/*1*之后添加适当的语句。 (2)完成类 CRectangle的成员函数getperimeter()的定义,将以 a和 b为边的矩形周长的值返回,请在注释“/*2*”之后添加适当的语句。 (3)完成类 CRectangle的成员函数 getarea()的定义,将以 a和 b为边的矩形面积的值返回,请在注释“/*3*”之后添加适当的语句。 (4)完成类 CRectangle的友元函数 friend double dist(CRectangle double y; double a; double b; public: CRectangle() cout

6、/nCRectangle Constructed.“endl; CRectangle(double dx, double dy, double da, double db) /*1* a=da; b=db; cout“/nCRectangle Constructed.“endl; CRectangle ( ) cout“CRectangle Destructed.“endl; void putxy(double dx, double dy) x=dx; y=dy; void putab(double da, double db)( a=da; b=db; double getx() retu

7、rn x; double gety() return y; double geta() return a; double getb() return b; double getperimeter() /*2* double getarea() /*3* friend double dist(CRectangle ; double dist(CRectangle return sqrt(tx*tx+ty*ty); void main() CRectangle rect; rect.putxy(100.0, 50.0); rect.putab(1200.0, 700.0); cout“Down_L

8、eft corner point is: (“rect.getx() “, “rect.gety()“)“ endl; cout“a= “rect.geta()“, b=“rect.getb() endl; cout“Perimeter of this rectangle is: “rect.getperimeter()endl; cout“Area of this rectangle is:“rect.getarea()endl; cout“The Distance is:“dist(rect)endl; CRectangle recta(200,150,2000,800); cout“Do

9、wn_Left corner point is:(“recta.getx()“,“recta.gety()“)“endl; cout“a=“recta.geta()“, b=“recta.getb()endl; cout“Perimeter of this rectangle is: “recta.getperimeter()endl; cout“Area of this rectangle is: “recta.getarea()endl; cout“The Distance is :“dist(recta)endl; (分数:30.00)_二级 C+机试 18答案解析(总分:100.00,

10、做题时间:90 分钟)一、B1改错题/B(总题数:1,分数:30.00)1.使用 VC6打开考生文件夹下的工程 test21_1,此工程包含一个源程序文件 test21_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下: The grade is 3 源程序文件 test21_1.cpp清单如下: #includeiostream.h class student private: int grade; public: /* found*/ student(int thegra):(thegra) student() int get_grade()return grade

11、 ; void main() int thegra=3; /* found*/ student point=new student(thegra); /* found*/ cout“The grade is“point.get_grade()endl; delete point; (分数:30.00)解析:(1)错误:student(int thegra):(thegra) 正确:student(int thegra):grade(thegra) (2)错误:student point=new student(thegra) 正确:student*point=new student(theg

12、ra); (3)错误:cout“The grade is“point.get_grade()endl; 正确:cout“The grade is“point-get_grade()endl; 解析 (1)主要考查考生对于构造函数使用参数列表初始化数据成员的掌握,可以使用参数列表的形式,也可以在函数内部实现,不过参数赋值的双方都必须出现,本题的错误就在于并没有把参数赋值给数据成员; (2)主要考查考生对于使用指针申请动态空间的方法的理解,new 运算符申请的空间返回值为指针类型,指针类型的定义是在变量名前加上“*”; (3)主要考查考生对于对象指针调用成员函数方法的掌握,必须使用符号“-”,而对

13、象本身使用符号“.”。二、B2简单应用题/B(总题数:1,分数:40.00)2.请编写一个函数 char*change(char instr),将输入字符串中的所有小写字母转换为大写字母输出。要求使用 for循环实现。如输入 jinfeiteng,则输出结果是 JINFEITENG。 注意:部分源程序已存在文件test21_2.cpp中。 请勿修改主函数 main和其他函数中的任何内容,仅在函数 change的花括号中填写若干语句。 文件 test21_2.cpp的内容如下: char*change(char instr); #include“iostream.h“ void main() c

14、har instr50; char *outstr; cout“Input a string:“endl; cininstr; outstr=change(instr); cout“Over graded string:“endl; coutoutstrendl; char*change(char instr) (分数:40.00)_正确答案:()解析:char *change(char instr) char *outstr=new char50; const char delta=A-a; int i; for(i=0;instri!=/0;i+) if(instri =a double

15、y; double a; double b; public: CRectangle() cout“/nCRectangle Constructed.“endl; CRectangle(double dx, double dy, double da, double db) /*1* a=da; b=db; cout“/nCRectangle Constructed.“endl; CRectangle ( ) cout“CRectangle Destructed.“endl; void putxy(double dx, double dy) x=dx; y=dy; void putab(doubl

16、e da, double db)( a=da; b=db; double getx() return x; double gety() return y; double geta() return a; double getb() return b; double getperimeter() /*2* double getarea() /*3* friend double dist(CRectangle ; double dist(CRectangle return sqrt(tx*tx+ty*ty); void main() CRectangle rect; rect.putxy(100.

17、0, 50.0); rect.putab(1200.0, 700.0); cout“Down_Left corner point is: (“rect.getx() “, “rect.gety()“)“ endl; cout“a= “rect.geta()“, b=“rect.getb() endl; cout“Perimeter of this rectangle is: “rect.getperimeter()endl; cout“Area of this rectangle is:“rect.getarea()endl; cout“The Distance is:“dist(rect)e

18、ndl; CRectangle recta(200,150,2000,800); cout“Down_Left corner point is:(“recta.getx()“,“recta.gety()“)“endl; cout“a=“recta.geta()“, b=“recta.getb()endl; cout“Perimeter of this rectangle is: “recta.getperimeter()endl; cout“Area of this rectangle is: “recta.getarea()endl; cout“The Distance is :“dist(recta)endl; (分数:30.00)_正确答案:()解析:(1) x=dx; y=dy; (2) return2*(a+b); (3) return a*b; (4) double tx,ty; tx=rt.x+rt.a/2.0; 解析本题主要考查考生对于类的定义和友元函数的定义的理解。注意(4)中使用了求开平方的数学函数 sqrt。

展开阅读全文
相关资源
猜你喜欢
  • EN 10307-2001 en Non-Destructive Testing - Ultrasonic Testing of Austenitic and Austenitic-Ferritic Stainless Steels Flat Products of Thickness Equal to or Greater Than 6 mm (Refle.pdf EN 10307-2001 en Non-Destructive Testing - Ultrasonic Testing of Austenitic and Austenitic-Ferritic Stainless Steels Flat Products of Thickness Equal to or Greater Than 6 mm (Refle.pdf
  • EN 10308-2001 en Non-Destructive Testing - Ultrasonic Testing of Steel Bars《无损检测 钢棒的超声波检测》.pdf EN 10308-2001 en Non-Destructive Testing - Ultrasonic Testing of Steel Bars《无损检测 钢棒的超声波检测》.pdf
  • EN 10310-2003 en Steel tubes and fittings for onshore and offshore pipelines -Internal and external polyamide powder based coatings《岸上和海上管道用钢管和配件 内外部聚酰胺粉末基涂层》.pdf EN 10310-2003 en Steel tubes and fittings for onshore and offshore pipelines -Internal and external polyamide powder based coatings《岸上和海上管道用钢管和配件 内外部聚酰胺粉末基涂层》.pdf
  • EN 10311-2005 en Joints for the connection of steel tubes and fittings for the conveyance of water and other aqueous liquids《水和其他含水液体传送用钢管和配件的连接用接头》.pdf EN 10311-2005 en Joints for the connection of steel tubes and fittings for the conveyance of water and other aqueous liquids《水和其他含水液体传送用钢管和配件的连接用接头》.pdf
  • EN 10312-2002 en Welded stainless steel tubes for the conveyance of aqueous liquids including water for human consumption Technical delivery conditions《传送人类消耗的含水液体(包括水)的焊焊接不锈钢管 交货技.pdf EN 10312-2002 en Welded stainless steel tubes for the conveyance of aqueous liquids including water for human consumption Technical delivery conditions《传送人类消耗的含水液体(包括水)的焊焊接不锈钢管 交货技.pdf
  • EN 10314-2002 7504 Method for the derivation of minimum values of proof strength of steel at elevated temperatures《高温下钢的校验强度最小值的推导方法 代替ENV 22605-1-1991 ENV 22605-2-1991和ENV 22605-3.pdf EN 10314-2002 7504 Method for the derivation of minimum values of proof strength of steel at elevated temperatures《高温下钢的校验强度最小值的推导方法 代替ENV 22605-1-1991 ENV 22605-2-1991和ENV 22605-3.pdf
  • EN 10314-2016 en Method for the derivation of minimum values of proof strength of steel at elevated temperatures《高温下钢保证强度最小值的导出法》.pdf EN 10314-2016 en Method for the derivation of minimum values of proof strength of steel at elevated temperatures《高温下钢保证强度最小值的导出法》.pdf
  • EN 10315-2006 en Routine method for analysis of high alloy steel by X-ray Fluorescence Spectrometry (XRF) by using a near by technique《使用临近技术用X射线荧光光谱法(XRF)分析高合金钢的常规法》.pdf EN 10315-2006 en Routine method for analysis of high alloy steel by X-ray Fluorescence Spectrometry (XRF) by using a near by technique《使用临近技术用X射线荧光光谱法(XRF)分析高合金钢的常规法》.pdf
  • EN 10318-2005 en Determination of thickness and chemical composition of zincand aluminium-based metallic coatings - Routine method《锌和铝基金属涂层的厚度和化学成分的测定 常规法》.pdf EN 10318-2005 en Determination of thickness and chemical composition of zincand aluminium-based metallic coatings - Routine method《锌和铝基金属涂层的厚度和化学成分的测定 常规法》.pdf
  • 相关搜索

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

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