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

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

1、二级 C+机试-46 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test18_1,此工程包含一个源程序文件 test18_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:Enter x and y:-4 -5xoffset=1yoffset=1angle=45radius=1.41421源程序文件 test18_1.cpp 清单如下:#include iostream.h#include math.hclass pointpublic:void set(double ix

2、double iy)x=ix;y=iy;double xoffset()return x;double yoffset()return y;double angle ( )return (180/3.14159)*atan2(y,x);/* found */inline radius ( )return sqrt(x*x+y*y);protected:double x;double y;void main()point p;double x,y;cout“Enter x and y:/n“;cinxy;p.set(x,y);/* found */p.x+=5;p.y+=6;/* found

3、/cout“xoffset=“p.xoffset()end1;cout“yoffset=“p.yoffset()end1;cout“angle=“p.angle()end1;cout“radius=“p.radius()end1;(分数:33.00)填空项 1:_二、2简单应用题(总题数:1,分数:33.00)2.编写函数 fun(),该函数的功能是从字符串中删除指定的字符,同一字母的大、小写按不同字符处理。例如:程序执行时输入字符串为 turbo c and borland c+,从键盘上输入字符 n,则输出后变为 turbo c ad borlad c+。如果输入的字符在字符串中不存在,

4、则字符串照原样输出。注意:部分源程序已存在文件 test18_2.cpp 中。请勿改动主函数脚 in 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。文件 test18_2.cpp 的内容如下:#includestdio.h#includeiostream.h#includeconio.hvoid fun(char s , int c)void main ( )static char str =“turbo c and borland c+“;char ch;cout“原始字符串:/n“strend1;cout“输入一个字符:“;cinch;fun(str.ch);c

5、out“str=“strend1;(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.使用 VC6 打开考生文件夹下的工程 test18_3,此工程包含一个源程序文件 test18_3.cpp,其中定义了用于表示雇员的类 Employee,但类 Employee 的定义并不完整。请按要求完成下列操作,将类 Employee的定义补充完整。(1)补充类 Employee 的构造函数,请使用字符串函数将数据成员 name,address,city,province 和zipcode 分别初始化为参数*nm,*addr,*city,*prov 和*zip 的值。请在注释“/*1

6、之后添加适当的语句;(2)完成类 Employee 的成员函数 ChangeName(char * newName)的定义,将 newName 指向的内容赋值给数据成员 name,请在注释“/*2*”之后添加适当的语句;(3)完成类 Employee 的成员函数 Display()的定义,先使用指针 buffer 动态申请一个 char 型的 200 单位大小的空间,然后使用字符串函数将数据成员 name 和 address 依次复制其中,最后返回该指针 buffer,将请在注释“/*3*”之后添加适当的语句。输出结果如下:王东建国路大街 105 号注意:除在指定位置添加语句之外,请不要改

7、动程序中的其他内容。源程序文件 test18_3.cpp 清单如下:#include iostream.h#include string.hclass Employeeprotected:char name20;char address100;char city20;char province20;char zipcode10;public:Employee(char *nm, char *addr,char *city, char *prov, char *zip);void ChangeName(char *newName);char *Display();Employee:Employe

8、e(char *nm, char *adr, char *cit, char *prov, char *zip)/*1*strcpy(city, cit);strcpy(province,prov);strcpy(zipcode,zip);void Employee:ChangeName(char * newName)/*2*char *Employee:Display()/*3*strcat(buffer, address);return buffer;void main()Employee emp(“李华“,“建国路大街 105 号“,“石家庄“,“河北“,“103400“);emp. C

9、hangeName (“王东“);coutemp.Display()end1;(分数:34.00)_二级 C+机试-46 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 test18_1,此工程包含一个源程序文件 test18_1.cpp,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:Enter x and y:-4 -5xoffset=1yoffset=1angle=45radius=1.41421源程序文件 test18_1.cpp 清单如下:#include iostream.h#i

10、nclude math.hclass pointpublic:void set(double ix,double iy)x=ix;y=iy;double xoffset()return x;double yoffset()return y;double angle ( )return (180/3.14159)*atan2(y,x);/* found */inline radius ( )return sqrt(x*x+y*y);protected:double x;double y;void main()point p;double x,y;cout“Enter x and y:/n“;ci

11、nxy;p.set(x,y);/* found */p.x+=5;p.y+=6;/* found */cout“xoffset=“p.xoffset()end1;cout“yoffset=“p.yoffset()end1;cout“angle=“p.angle()end1;cout“radius=“p.radius()end1;(分数:33.00)填空项 1:_ (正确答案:(1) 错误:inline radius()正确:inline double radius()(2) 错误:p.x+=5;p.y+=6;正确:p.set(p.xoffset()+5),(p.yoffset()+6);(3)

12、 应在结尾处添加“”)解析:解析(1)主要考查考生对于内联函数使用规则的掌握,虽然使用内联函数返回函数的值,但也要确定返回值的类型;(2)主要考查考生对于对象访问类的数据成员的权限的掌握,对象不能直接访问类的私有或保护成员,只能通过类的公有成员函数去访问;(3)主要考查考生对于主函数定义的掌握,该处缺少“”,函数体的花括号一定是成对出现的。二、2简单应用题(总题数:1,分数:33.00)2.编写函数 fun(),该函数的功能是从字符串中删除指定的字符,同一字母的大、小写按不同字符处理。例如:程序执行时输入字符串为 turbo c and borland c+,从键盘上输入字符 n,则输出后变为

13、 turbo c ad borlad c+。如果输入的字符在字符串中不存在,则字符串照原样输出。注意:部分源程序已存在文件 test18_2.cpp 中。请勿改动主函数脚 in 和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。文件 test18_2.cpp 的内容如下:#includestdio.h#includeiostream.h#includeconio.hvoid fun(char s , int c)void main ( )static char str =“turbo c and borland c+“;char ch;cout“原始字符串:/n“str

14、end1;cout“输入一个字符:“;cinch;fun(str.ch);cout“str=“strend1;(分数:33.00)_正确答案:(void fun(char s, int c)int i=0;char *p;p=s;while( *p)if( *p!=c)si=*p;i+;p+;si=/0;)解析:解析本题考查用字符指针来控制字符数组中的元素。指针 p 初始化时应指向字符数组的首地址s,之后利用 p 逐个取得数组中的元素,然后用取得的字符逐个与要删除的字符进行比较,如果二者相同,则跳过该字符,去取下一个数组元素,这样最终得到的字符串中就把要删除的字符去掉了。最后不要忘记要手动地加

15、上一个字符串结束标记/0。三、3综合应用题(总题数:1,分数:34.00)3.使用 VC6 打开考生文件夹下的工程 test18_3,此工程包含一个源程序文件 test18_3.cpp,其中定义了用于表示雇员的类 Employee,但类 Employee 的定义并不完整。请按要求完成下列操作,将类 Employee的定义补充完整。(1)补充类 Employee 的构造函数,请使用字符串函数将数据成员 name,address,city,province 和zipcode 分别初始化为参数*nm,*addr,*city,*prov 和*zip 的值。请在注释“/*1*”之后添加适当的语句;(2)

16、完成类 Employee 的成员函数 ChangeName(char * newName)的定义,将 newName 指向的内容赋值给数据成员 name,请在注释“/*2*”之后添加适当的语句;(3)完成类 Employee 的成员函数 Display()的定义,先使用指针 buffer 动态申请一个 char 型的 200 单位大小的空间,然后使用字符串函数将数据成员 name 和 address 依次复制其中,最后返回该指针 buffer,将请在注释“/*3*”之后添加适当的语句。输出结果如下:王东建国路大街 105 号注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件

17、 test18_3.cpp 清单如下:#include iostream.h#include string.hclass Employeeprotected:char name20;char address100;char city20;char province20;char zipcode10;public:Employee(char *nm, char *addr,char *city, char *prov, char *zip);void ChangeName(char *newName);char *Display();Employee:Employee(char *nm, cha

18、r *adr, char *cit, char *prov, char *zip)/*1*strcpy(city, cit);strcpy(province,prov);strcpy(zipcode,zip);void Employee:ChangeName(char * newName)/*2*char *Employee:Display()/*3*strcat(buffer, address);return buffer;void main()Employee emp(“李华“,“建国路大街 105 号“,“石家庄“,“河北“,“103400“);emp. ChangeName (“王东“

19、);coutemp.Display()end1;(分数:34.00)_正确答案:(1)strcpy(name,nm);strcpy(address,adr);(2)strcpy(name,newName);(3)char *buffer=new char200;strcpy(buffer,name);)解析:解析本题主要考查考生对于类的定义和字符串函数的灵活运用。算法如下:先使用 strchr 函数将名字中的空格找到,然后替换成为字符串结束标志,接着使用 strcpy 函数将被切断的字符串后面的部分复制到一个新的字符串 newName 中,再使用 strcat 函数连接“,”和原字符串的前半部分。

展开阅读全文
相关资源
猜你喜欢
  • ISO 228-2-1987 Pipe threads where pressure-tight joints are not made on the threads Part 2 Verification by means of limit gauges《非螺纹密封的管螺纹 第2部分 用极限量规检验》.pdf ISO 228-2-1987 Pipe threads where pressure-tight joints are not made on the threads Part 2 Verification by means of limit gauges《非螺纹密封的管螺纹 第2部分 用极限量规检验》.pdf
  • ISO 22803-2004 Dentistry - Membrane materials for guided tissue regeneration in oral and maxillofacial surgery - Contents of a technical file《牙科学 口腔及颌面外科中受控制的组织.pdf ISO 22803-2004 Dentistry - Membrane materials for guided tissue regeneration in oral and maxillofacial surgery - Contents of a technical file《牙科学 口腔及颌面外科中受控制的组织.pdf
  • ISO 22810-2010 Horology - Water-resistant watches《钟表 防水水表》.pdf ISO 22810-2010 Horology - Water-resistant watches《钟表 防水水表》.pdf
  • ISO 22825-2017 Non-destructive testing of welds - Ultrasonic testing - Testing of welds in austenitic steels and nickel-based alloys《焊缝无损检测 超声波试验 奥氏体刚和镍合金焊缝试验》.pdf ISO 22825-2017 Non-destructive testing of welds - Ultrasonic testing - Testing of welds in austenitic steels and nickel-based alloys《焊缝无损检测 超声波试验 奥氏体刚和镍合金焊缝试验》.pdf
  • ISO 22826-2005 Destructive tests on welds in metallic materials - Hardness testing of narrow joints welded by laser and electron beam (Vickers and Knoop hardnes.pdf ISO 22826-2005 Destructive tests on welds in metallic materials - Hardness testing of narrow joints welded by laser and electron beam (Vickers and Knoop hardnes.pdf
  • ISO 2283-2000 Long shank taps with nominal diameters from M3 to M24 and 1 8 in to 1 in - Reduced shank taps《公称直径从M3~M24和1 8英寸~1英寸的长柄机用丝锥-缩柄丝锥》.pdf ISO 2283-2000 Long shank taps with nominal diameters from M3 to M24 and 1 8 in to 1 in - Reduced shank taps《公称直径从M3~M24和1 8英寸~1英寸的长柄机用丝锥-缩柄丝锥》.pdf
  • ISO 22846-1-2003 Personal equipment for protection against falls - Rope access systems - Part 1 Fundamental principles for a system of work《个人防跌落保护性设备 绳索接近系统 第1.pdf ISO 22846-1-2003 Personal equipment for protection against falls - Rope access systems - Part 1 Fundamental principles for a system of work《个人防跌落保护性设备 绳索接近系统 第1.pdf
  • ISO 22855-2008 Fruit and vegetable products - Determination of benzoic acid and sorbic acid concentrations - High-performance liquid chromatography method《水果和蔬菜.pdf ISO 22855-2008 Fruit and vegetable products - Determination of benzoic acid and sorbic acid concentrations - High-performance liquid chromatography method《水果和蔬菜.pdf
  • ISO 22856-2008 Equipment for crop protection - Methods for the laboratory measurement of spray drift - Wind tunnels《植保设备 喷雾漂移的实验室测量方法 风洞》.pdf ISO 22856-2008 Equipment for crop protection - Methods for the laboratory measurement of spray drift - Wind tunnels《植保设备 喷雾漂移的实验室测量方法 风洞》.pdf
  • 相关搜索
    资源标签

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

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