【计算机类职业资格】2010秋江苏省计算机二级C++上机1及答案解析.doc

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

1、2010 秋江苏省计算机二级 C+上机 1 及答案解析(总分:40.00,做题时间:70 分钟)1.改错题(20 分) 【题目】 以下程序的功能是:根据字符串 str 中是否包含子串 substr,决定如何将字符串 str1 插入到 str 的不同位置。插入方法是:如果 str 中包含子串 substr,则将 str1 插入到 str 中首次出现的子串 substr 之后;否则,插入到 str 的尾部。 正确程序的输出如下: 原字符串:aabcd12345 子字符串:abcd 插入字符串:ABC 新字符串:aabcdABC12345 含有错误的源程序如下: #include #include

2、char *find(char *str,char *substr) unsigned lent=strlen(str); for(char *p1=str,*p2=substr;strlen(p1)=len;p1+) for(unsigned i=0;ilen) return p1+len; return 0; char *insert(char *str,char *substr,char *str1) char p=find(str,substr); if(p) strcat(str,str1); else char *tmp=new charstrlen(str)+strlen(str

3、1)+1; strcpy(tmp,str1) strcat(tmp,p); strcpy(p,tmp); delete tmp; return str; void main() char *str=new char80,substr=“abcd“,str1=“ABC“; strcpy(str,“aabcdl2345“); cout=len;p1+) for(unsigned i=0;ilen) return p1+len; return 0; char *insert(char *str,char *substr,char *str1) char p=find(str,substr); if(

4、p) strcat(str,str1); else char *tmp=new charstrlen(str)+strlen(str1)+1; strcpy(tmp,str1) strcat(tmp,p); strcpy(p,tmp); delete tmp; return str; void main() char *str=new char80,substr=“abcd“,str1=“ABC“; strcpy(str,“aabcdl2345“); coutlen) 改为 i=len char p=find(str,substr); char p 改为 char *p if(p) p 改为

5、p=0 或!p)解析:2.编程题(20 分) 【题目】 试定义一个类 Array,将 4 行 5 列二维数组的各列前 3 个元素依次拼接成一个整数,再将该整数赋值给相应列的最后一个元素。例如, (1)私有数据成员: int a45; (2)公有成员函数。 Array(int b5,int n):构造函数,用二维数组 b 初始化数组 a,参数 n 表示数组 b 的行数。 void val(int j):将成员数组 a 第 j 列的前 3 个元素依次拼接成一个整数赋值给第 4 个元素。 void fun():利用成员函数 vaLl()依次处理数组 a 的各列,完成题目的要求。 void print

6、):按矩阵形式打印数组 a。 (3)在主函数中完成对该类的测试。 输出示例: 原数组: 1 2 0 4 1 16 11 21 0 2 2 0 3 1 3 0 0 0 0 0 处理后的数组: l 2 0 4 1 16 11 21 0 2 2 0 3 1 3 1162 2110 213 401 123 【要求】 源程序文件名必须为myfbcpp,并放在 T 盘根目录下,供阅卷用。(分数:20.00)_正确答案:( #include class Array int a45; public: Array(int b5,int n) for(int i=0;iaij/t; cout/n; void main() int t45=1,2,0,4,1,16,11,21,0,2,2,0,3,1,3; Array test(t,4); cout“原数组:“处理后的数组:“解析:

展开阅读全文
相关资源
猜你喜欢
  • BS ISO 2906-2002 Cinematography - Image area produced by camera aperture on 35mm motion picture film - Position and dimensions《电影技术 用摄象机快门在35mm电影胶片上形成的影象区 位置和尺寸》.pdf BS ISO 2906-2002 Cinematography - Image area produced by camera aperture on 35mm motion picture film - Position and dimensions《电影技术 用摄象机快门在35mm电影胶片上形成的影象区 位置和尺寸》.pdf
  • BS ISO 29061-1-2011 Road vehicles Methods and criteria for usability evaluation of child restraint systems and their interface with vehicle anchorage systems Vehicles and child resn.pdf BS ISO 29061-1-2011 Road vehicles Methods and criteria for usability evaluation of child restraint systems and their interface with vehicle anchorage systems Vehicles and child resn.pdf
  • BS ISO 2907-2003 Cinematography - Maximum projectable image area on 35 mm motion-picture film - Position and dimensions《电影 35mm电影胶片上最大可放映画面区域 位置和尺寸》.pdf BS ISO 2907-2003 Cinematography - Maximum projectable image area on 35 mm motion-picture film - Position and dimensions《电影 35mm电影胶片上最大可放映画面区域 位置和尺寸》.pdf
  • BS ISO 29081-2010 Surface chemical analysis - Auger electron spectroscopy - Reporting of methods used for charge control and charge correction《表面化学分析 俄歇电子能谱法 电荷控制和电荷调整用报告法》.pdf BS ISO 29081-2010 Surface chemical analysis - Auger electron spectroscopy - Reporting of methods used for charge control and charge correction《表面化学分析 俄歇电子能谱法 电荷控制和电荷调整用报告法》.pdf
  • BS ISO 2911-2004 Sweetened condensed milk - Determination of sucrose content - Polarimetric method《甜炼乳 蔗糖含量的测定 旋光法》.pdf BS ISO 2911-2004 Sweetened condensed milk - Determination of sucrose content - Polarimetric method《甜炼乳 蔗糖含量的测定 旋光法》.pdf
  • BS ISO 2920-2004 Whey cheese - Determination of dry matter (Reference method)《乳清干酪 干(燥)物质含量的测定(参照法)》.pdf BS ISO 2920-2004 Whey cheese - Determination of dry matter (Reference method)《乳清干酪 干(燥)物质含量的测定(参照法)》.pdf
  • BS ISO 2921-2011 Rubber vulcanized Determination of low-temperature retraction (TR test)《硫化橡胶 低温回缩(TR试验)的测定》.pdf BS ISO 2921-2011 Rubber vulcanized Determination of low-temperature retraction (TR test)《硫化橡胶 低温回缩(TR试验)的测定》.pdf
  • BS ISO 29221-2014 Plastics Determination of mode I plane-strain crack-arrest toughness《塑料 模式I平面应变止裂韧性的测定》.pdf BS ISO 29221-2014 Plastics Determination of mode I plane-strain crack-arrest toughness《塑料 模式I平面应变止裂韧性的测定》.pdf
  • BS ISO 2926-2013 Aluminium oxide used for the production of primary aluminium Particle size analysis for the range 45 $GMm to 150 $GMm Method using electroformed sieves《主要用于铝生产的氧化铝.pdf BS ISO 2926-2013 Aluminium oxide used for the production of primary aluminium Particle size analysis for the range 45 $GMm to 150 $GMm Method using electroformed sieves《主要用于铝生产的氧化铝.pdf
  • 相关搜索

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

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