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

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

1、二级 C+-13-2 及答案解析(总分:100.00,做题时间:90 分钟)一、程序改错题(总题数:1,分数:30.00)1.使用 VC+6.0 打开 下的源程序文件 1.cpp,使它能运行正确的结果。 注意:不要改动其他语句,不得增行或删行,也不得更改程序的结构! 本程序要求屏幕输出:i=12345 注意:语句在/*error*/的下面。修改该语句即可,其他的语句不能修改。 试题程序: #includeiostream.h /*error*/ class TC() public: /*error*/ voidTC() TC(int i) cout“i“=“iendl; /*error*/ v

2、oid main() TC obj(12345); return; (分数:30.00)_二、简单应用题(总题数:1,分数:30.00)2.使用 VC+6.0 打开 下的源程序文件 2.cpp。完成空出函数 fun(char * s,char * t)部分。函数fun(cha * s,char * t)的功能是将在字符串 s 中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串 t 中,t 中字符按原字符串中字符的顺序排列。 例如:当 s 中的字符串为“ABCDEF”时,t 中的字符串应为“AACCEE”。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程

3、序: #includeiostream.h vold fun(char * s,char * t) ) void main() char s100,t100; cout“Please enter string s:“endl; cin.getline(s,100); fun(s,t); cout“The result is:“tendl; return; (分数:30.00)_三、综合应用题(总题数:1,分数:40.00)3.使用 VC+6.0 打开 下的源程序文件 3.cpp,其中定义了用于表示日期的类 Date,但类 Date 的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1

4、)定义私有成员变量 year、month、day,分别表示年、月、日,类型为 int。请在注释 1 后添加适当的语句。 (2)完成构造函数,分别给 year、month、day 赋值,请在注释 2 后添加适当的语句。 (3)完成重载符号“+=”的定义,请在注释 3 后添加适当的语句。 (4)完成函数 print 打印函数,如 2005 年 1 月 5 日到屏幕和文件 out3.txt 格式相同,请在注释 4 后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。 试题程序: #includeiostream.h #includefstream2 #

5、includeiomanip #includecmath using namespace std; void WriteFile(int c) ofstream out1; out1.open(“out3.txt“,ios_base:app); out1c“; out1.close(); void WriteFik(char*Str) ofstream out1; out1.open(“out3.txt“,ios_base:app); out1str; out1.close(); void ClearFile() ofstream out1; out1.open(“out3.txt“); ou

6、t1.close(); class Date public: Date(int y,int m,int d) /*1* void print(); /*2* month+=m; int i=month/12; int j=month%12; if(j=0) year+=(i-1); month=12; else year+=i; month=j; return * this; private: /*3* ; void Date:print() /*4* WriteFile(year); WriteFile(“年“); WriteFile(month); WriteFile(“月“); Writ

7、eFile(day); WriteFile(“日“); int main() ClearFile(); Date National_day(2004,10,5); National_day+=3; National_day.print(); return 0; (分数:40.00)_二级 C+-13-2 答案解析(总分:100.00,做题时间:90 分钟)一、程序改错题(总题数:1,分数:30.00)1.使用 VC+6.0 打开 下的源程序文件 1.cpp,使它能运行正确的结果。 注意:不要改动其他语句,不得增行或删行,也不得更改程序的结构! 本程序要求屏幕输出:i=12345 注意:语句在/

8、error*/的下面。修改该语句即可,其他的语句不能修改。 试题程序: #includeiostream.h /*error*/ class TC() public: /*error*/ voidTC() TC(int i) cout“i“=“iendl; /*error*/ void main() TC obj(12345); return; (分数:30.00)_正确答案:()解析:(1)“class TC()”应改为“class TC”。 (2)“voidTC()”应改为“TC()”。 (3)“”应改为“;”。 答案考生文件夹 解析 本题考查了考生对类的定义了解的情况。类定义类名后不能

9、有括号,所以第 1 处应该是“class TC”。类的析构函数不能有返回类型,所以应改为“TC()”。最容易忽略的地方,就是类定义之后必须跟一个分号。因为类的定义属于类型定义语句,就好像定义一个结构、用 typedef 关键字定义一个类型的别名一样,其后都要跟语句结束标志“;”。二、简单应用题(总题数:1,分数:30.00)2.使用 VC+6.0 打开 下的源程序文件 2.cpp。完成空出函数 fun(char * s,char * t)部分。函数fun(cha * s,char * t)的功能是将在字符串 s 中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串 t 中,t 中字符按

10、原字符串中字符的顺序排列。 例如:当 s 中的字符串为“ABCDEF”时,t 中的字符串应为“AACCEE”。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includeiostream.h vold fun(char * s,char * t) ) void main() char s100,t100; cout“Please enter string s:“endl; cin.getline(s,100); fun(s,t); cout“The result is:“tendl; return; (分数:30.00)_正确答案:()解析:void

11、fun(char * s,char * t) int i; for(i=0;si! =0;i+) if(i%2=0) ti=si; ti+2=“/0“; 答案考生文件夹 解析 本题要求将在字符串 s 中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串 t 中,t 中字符按原字符串中字符的顺序排列,也就是说重复出现一次偶数位的字符,数组的下标是从 0 开始的,所以会重复第 1、3、5的字符。三、综合应用题(总题数:1,分数:40.00)3.使用 VC+6.0 打开 下的源程序文件 3.cpp,其中定义了用于表示日期的类 Date,但类 Date 的定义并不完整,按要求完成下列操作,将类

12、的定义补充完整。 (1)定义私有成员变量 year、month、day,分别表示年、月、日,类型为 int。请在注释 1 后添加适当的语句。 (2)完成构造函数,分别给 year、month、day 赋值,请在注释 2 后添加适当的语句。 (3)完成重载符号“+=”的定义,请在注释 3 后添加适当的语句。 (4)完成函数 print 打印函数,如 2005 年 1 月 5 日到屏幕和文件 out3.txt 格式相同,请在注释 4 后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。 试题程序: #includeiostream.h #includ

13、efstream2 #includeiomanip #includecmath using namespace std; void WriteFile(int c) ofstream out1; out1.open(“out3.txt“,ios_base:app); out1c“; out1.close(); void WriteFik(char*Str) ofstream out1; out1.open(“out3.txt“,ios_base:app); out1str; out1.close(); void ClearFile() ofstream out1; out1.open(“out

14、3.txt“); out1.close(); class Date public: Date(int y,int m,int d) /*1* void print(); /*2* month+=m; int i=month/12; int j=month%12; if(j=0) year+=(i-1); month=12; else year+=i; month=j; return * this; private: /*3* ; void Date:print() /*4* WriteFile(year); WriteFile(“年“); WriteFile(month); WriteFile

15、月“); WriteFile(day); WriteFile(“日“); int main() ClearFile(); Date National_day(2004,10,5); National_day+=3; National_day.print(); return 0; (分数:40.00)_正确答案:()解析:(1)应添加“year=y;month=m;day=d;”。 (2)应添加“Date”。 (4)应添加“coutyear“年“month“月“day“日“endl;”。 答案考生文件夹 解析 本题要求私有成员变量 year、month、day 为整形表示方法,所以注释 3 应添加“int year,month,day;”;注释 1 要求分别给 year、month、day 赋值,根据上下文提意,所以应添加“year=y;month=m;day=d;”;注释 2 是对“+=”运算符的重载,Date&operator+=(int m);第 4 处打印输出年、月、日,C+语言中,输出使用 cout。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 4292-2006 Aerospace series - Aluminium alloy AL-R39002 - Forging stock German and English version EN 4292 2005《航空航天系列 铝合金AL-R39002 锻坯》.pdf DIN EN 4292-2006 Aerospace series - Aluminium alloy AL-R39002 - Forging stock German and English version EN 4292 2005《航空航天系列 铝合金AL-R39002 锻坯》.pdf
  • DIN EN 4293-2014 Aerospace series - Aluminium alloy AL-P7175 - T73511 - Extruded bar and section - a or D = 150 mm German and English version EN 4293 2014《航空航天系列 铝合金AL-P7175 T73511.pdf DIN EN 4293-2014 Aerospace series - Aluminium alloy AL-P7175 - T73511 - Extruded bar and section - a or D = 150 mm German and English version EN 4293 2014《航空航天系列 铝合金AL-P7175 T73511.pdf
  • DIN EN 4297-2017 Aerospace series - Nuts hexagon self-locking by plastic ring normal height normal across flats in corrosion resisting steel passivated - Classification 900 MPa (at.pdf DIN EN 4297-2017 Aerospace series - Nuts hexagon self-locking by plastic ring normal height normal across flats in corrosion resisting steel passivated - Classification 900 MPa (at.pdf
  • DIN EN 4300-2009 Aerospace series - Identification marking of engine items - Design standard German and English version EN 4300 2008《航空航天系列 发动机项目的识别标识 设计标准》.pdf DIN EN 4300-2009 Aerospace series - Identification marking of engine items - Design standard German and English version EN 4300 2008《航空航天系列 发动机项目的识别标识 设计标准》.pdf
  • DIN EN 4301-2009 Aerospace series - Identification marking methods for engine items - Engineering requirements German and English version EN 4301 2009《航空航天系列 发动机的打印标号 工程要求 德文和英文版本E.pdf DIN EN 4301-2009 Aerospace series - Identification marking methods for engine items - Engineering requirements German and English version EN 4301 2009《航空航天系列 发动机的打印标号 工程要求 德文和英文版本E.pdf
  • DIN EN 4302-2009 Aerospace series - Open ring insert tool square drive German and English version EN 4302 2008《航空航天系列 方形驱动开环插入工具》.pdf DIN EN 4302-2009 Aerospace series - Open ring insert tool square drive German and English version EN 4302 2008《航空航天系列 方形驱动开环插入工具》.pdf
  • DIN EN 4303-2006 Aerospace series - Sleeves tubular for tension screws with flush head in corrosion resisting steel passivated (0 25 mm wall thickness) German and English version E.pdf DIN EN 4303-2006 Aerospace series - Sleeves tubular for tension screws with flush head in corrosion resisting steel passivated (0 25 mm wall thickness) German and English version E.pdf
  • DIN EN 4304-2007 Aerospace series - Sleeves tubular for shear screws with flush head in corrosion resisting steel passivated (0 25 mm wall thickness) German and English version EN .pdf DIN EN 4304-2007 Aerospace series - Sleeves tubular for shear screws with flush head in corrosion resisting steel passivated (0 25 mm wall thickness) German and English version EN .pdf
  • DIN EN 4306-2007 Aerospace series - Sleeves tubular for tension screws with flush head in corrosion resisting steel passivated (0 50 mm wall thickness) German and English version E.pdf DIN EN 4306-2007 Aerospace series - Sleeves tubular for tension screws with flush head in corrosion resisting steel passivated (0 50 mm wall thickness) German and English version E.pdf
  • 相关搜索

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

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