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

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

1、二级 C+机试-98 及答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 RevProj9。此工程包含一个源程序文件 RevMain9.cpp。在该文件中,函数 fun()的功能是;将字符串 s 中的小写字母都改为对应的大写字母,其他字符不变。例如,输入“mT+gN”,则输出“MT+GN”。请改正程序中的错误,使它能得到正确结果。注意,不要改动 main 函数,不得删行或增行,也不得更改程序的结构。源程序文件 RevMain9.cpp 中的程序清单如下;/RevMain9.cpp#includeiostre

2、amusing namespace std;char* fun(char*s);int main()int i;char str81;cout“Please enter a string:“;cinstr;cout“/n The result is:/n“fun(str)end1;return 0;char *fun(char*s)int i;for(i=0;si;i+)/* * * * *FOUND* * * * *if(a=si)|(si:=z)/* * * * *FOUND * * * * * /si+=32;return s;(分数:33.00)_二、2简单应用题(总题数:1,分数:3

3、3.00)2.请编写一个函数 void fun(int p,int n,int c),其中数组 p 的元素按由小到大的顺序排列,其元素个数为 n。函数 fun()的功能是将 c 插入到数组 p 中,且保持数组的升序排列。注意:部分源程序已存在文件 PROC9.cpp 中。请勿修改主函数和其他函数中的任何内容,仅在函数 fun()的花括号中填写若干语句;文件 PROC9.cpp 的内容如下:/PROC9.cpp#include iostream#include stringusing namespace std;#define M 30void fun(int p ,int n,int c);i

4、nt main ()int ppM,n,i;int fg, c;cout“Please input n:/n“;cinn;cout“Please input the n data:/n“;for (i=0; in; i+)cinpp i;cout“Please input c:/n“;cinc;fun (pp, n, c);for (i=0; in; i+)coutpp i “ “ ;coutend1;return 0;void fun(int p ,int n, int c)/* * * * * * * * *(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.retu

5、rn 0;(分数:34.00)_二级 C+机试-98 答案解析(总分:100.00,做题时间:90 分钟)一、1改错题(总题数:1,分数:33.00)1.使用 VC6 打开考生文件夹下的工程 RevProj9。此工程包含一个源程序文件 RevMain9.cpp。在该文件中,函数 fun()的功能是;将字符串 s 中的小写字母都改为对应的大写字母,其他字符不变。例如,输入“mT+gN”,则输出“MT+GN”。请改正程序中的错误,使它能得到正确结果。注意,不要改动 main 函数,不得删行或增行,也不得更改程序的结构。源程序文件 RevMain9.cpp 中的程序清单如下;/RevMain9.cp

6、p#includeiostreamusing namespace std;char* fun(char*s);int main()int i;char str81;cout“Please enter a string:“;cinstr;cout“/n The result is:/n“fun(str)end1;return 0;char *fun(char*s)int i;for(i=0;si;i+)/* * * * *FOUND* * * * *if(a=si)|(si:=z)/* * * * *FOUND * * * * * /si+=32;return s;(分数:33.00)_正确答案

7、正确的 fun 函数如下:char *fun(char *s)int i;for(i=0;si;i+)if(a=si)#define M 30void fun(int p ,int n,int c);int main ()int ppM,n,i;int fg, c;cout“Please input n:/n“;cinn;cout“Please input the n data:/n“;for (i=0; in; i+)cinpp i;cout“Please input c:/n“;cinc;fun (pp, n, c);for (i=0; in; i+)coutpp i “ “ ;cou

8、tend1;return 0;void fun(int p ,int n, int c)/* * * * * * * * *(分数:33.00)_正确答案:(函数 fun()的定义如下:void fun(int p,int n,int c)int i;for(i=0;in&cpi;i+)memmove(p+i+1,p+x,sizeof(int)*(n-i);pi=c;)解析:解析 函数 fun()的功能是将 c 插入到数组 p 中,且保持数组的升序排列。可以首先用循环体宋扫描数组 p,遇到第一个大于或等于 c 的元素时,记下此时的下标值。然后将此元素以及此后的元素整体右移一个元素位置。然后把

9、c 赋值给此元素。三、3综合应用题(总题数:1,分数:34.00)3.return 0;(分数:34.00)_正确答案:(classCircle:public PointCircle(int a,int b,int c):Point(a,b)r=c;return PI*r*r;)解析:解析本程序设计了一个点类 Point,包含了横、纵两个坐标数据 x 和 y,由它公有派生出了圆类Circle,并加入了新的数据成员,即一个半径数据 r 和一个求圆面积的函数成员 area()。在主函数中,首先定义了一个圆 Circle 类的对象 c1,并通过它的构造函数初始化其数据成员。由此可知,其半径 r 的值为 10,所以其面积为 PI*10*10=314,即对象 c1 的函数成员 area()的返回值为 314。

展开阅读全文
相关资源
猜你喜欢
  • ISO 15089-2000 Water quality - Guidelines for selective immunoassays for the determination of plant treatment and pesticide agents《水质 测定植物处理和杀虫剂的选择性免疫法指南》.pdf ISO 15089-2000 Water quality - Guidelines for selective immunoassays for the determination of plant treatment and pesticide agents《水质 测定植物处理和杀虫剂的选择性免疫法指南》.pdf
  • ISO 1509-1973 General purpose push-pull three-pole circuit-breakers for aircraft Performance requirements《航空器的一般用途推拉式三极断路器 性能要求》.pdf ISO 1509-1973 General purpose push-pull three-pole circuit-breakers for aircraft Performance requirements《航空器的一般用途推拉式三极断路器 性能要求》.pdf
  • ISO 15098-1-1999 Dental tweezers - Part 1 General requirements《牙科镊子 第1部分 一般要求》.pdf ISO 15098-1-1999 Dental tweezers - Part 1 General requirements《牙科镊子 第1部分 一般要求》.pdf
  • ISO 15099-2003 Thermal performance of windows doors and shading devices - Detailed calculations《门、窗和遮蔽装置的热性能 详细计算》.pdf ISO 15099-2003 Thermal performance of windows doors and shading devices - Detailed calculations《门、窗和遮蔽装置的热性能 详细计算》.pdf
  • ISO 15100-2000 Plastics - Reinforcement fibres - Chopped strands Determination of bulk density《塑料 增强纤维 短切原丝 体积密度的测定》.pdf ISO 15100-2000 Plastics - Reinforcement fibres - Chopped strands Determination of bulk density《塑料 增强纤维 短切原丝 体积密度的测定》.pdf
  • ISO 15106-1-2003 Plastics Film and sheeting - Determination of water vapour transmission rate - Part 1 Humidity detection sensor method《塑料 薄膜和薄片 水蒸气传输率的测定 第1部分 .pdf ISO 15106-1-2003 Plastics Film and sheeting - Determination of water vapour transmission rate - Part 1 Humidity detection sensor method《塑料 薄膜和薄片 水蒸气传输率的测定 第1部分 .pdf
  • ISO 15106-2-2003 Plastics Film and sheeting - Determination of water vapour transmission rate - Part 2 Infrared detection sensor method《塑料 薄膜和薄片 水蒸气传输率的测定 第2部分 .pdf ISO 15106-2-2003 Plastics Film and sheeting - Determination of water vapour transmission rate - Part 2 Infrared detection sensor method《塑料 薄膜和薄片 水蒸气传输率的测定 第2部分 .pdf
  • ISO 15106-3-2003 Plastics Film and sheeting - Determination of water vapour transmission rate - Part 3 Electrolytic detection sensor method《塑料 薄膜和薄片 水蒸气传输率的测定 第.pdf ISO 15106-3-2003 Plastics Film and sheeting - Determination of water vapour transmission rate - Part 3 Electrolytic detection sensor method《塑料 薄膜和薄片 水蒸气传输率的测定 第.pdf
  • ISO 15106-4-2008 Plastics - Film and sheeting - Determination of water vapour transmission rate - Part 4 Gas-chromatographic detection sensor method《塑料 薄膜和薄板 水蒸.pdf ISO 15106-4-2008 Plastics - Film and sheeting - Determination of water vapour transmission rate - Part 4 Gas-chromatographic detection sensor method《塑料 薄膜和薄板 水蒸.pdf
  • 相关搜索

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

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