【计算机类职业资格】国家二级C++机试(操作题)模拟试卷406及答案解析.doc

上传人:cleanass300 文档编号:1331901 上传时间:2019-10-17 格式:DOC 页数:3 大小:35KB
下载 相关 举报
【计算机类职业资格】国家二级C++机试(操作题)模拟试卷406及答案解析.doc_第1页
第1页 / 共3页
【计算机类职业资格】国家二级C++机试(操作题)模拟试卷406及答案解析.doc_第2页
第2页 / 共3页
【计算机类职业资格】国家二级C++机试(操作题)模拟试卷406及答案解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级 C+机试(操作题)模拟试卷 406 及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6 打开考生文件夹下的源程序文件 modilcpp。本程序要求输入一字符串,然后将其中的小写字母改变成大写字母,字符可能输入多行,当输入字符“?”时,默认字符输入结束,最后把结果输出到界面。 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在*error*的下面。#includeiostreamhvoid main()( int i=0; char str120; cout”Enter a string end

2、with?“end1; *error* cingetline(str,120); *error* while(Str) *error* if(stri=a) Stri =Stri -a+A; i+; ) coutstrend1; return;(分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.使用 VC6 打开考生文件夹下的源程序文件 modi2cpp。完成函数 fun(char*str,char*s)空出部分。函数 fun(char*str,char* s)的功能是:将在字符串 str 中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串 s 中,s 中字符按原字符

3、串中字符的顺序排列。(注意 0 为偶数) 例如:当 str 中的字符串为:“abcdef“时,s 中的字符串应为:“aacccc“。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 #include void fun(char* str,char* s) void main() char str100,S100; cout=a&stri=a)”语句是判断字符 stri是否为小写字符,而现有的语句只是判断字符是否大于a,但是小写字符应该是a到z,所以修改为“if(stri=a&stri=z)”。二、简单应用题(总题数:1,分数:2.00)2.使用 VC6 打开考生文件夹

4、下的源程序文件 modi2cpp。完成函数 fun(char*str,char*s)空出部分。函数 fun(char*str,char* s)的功能是:将在字符串 str 中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串 s 中,s 中字符按原字符串中字符的顺序排列。(注意 0 为偶数) 例如:当 str 中的字符串为:“abcdef“时,s 中的字符串应为:“aacccc“。 注意:不要改动 main()函数,不得增行或删行,也不得更改程序的结构。 #include void fun(char* str,char* s) void main() char str100,S100;

5、 cout“Please enter strinq String:“The result is: “_正确答案:(正确答案:int 1; for(i=0;stri!=0;i+) 循环 判断每一个字符 if(i2=0) 判断字符串 中下标为偶数位置 si=stri; si+1=stri; si+2=0; 新串添加尾符 )解析:解析:(1)判断一个字符串中的某一字符下标 i 是否为偶数,可用“i2=0”来判断。 (2)对串str 中各个字符串逐个进行考查,满足条件的字符就顺序放在新串 S 中,否则就不存放。 (3)所有字符处理完后,记得在新串 S 的末尾加上结束符“0”。三、综合应用题(总题数:1

6、分数:2.00)3.使用 VC6 打开考生文件夹下的源程序文件 modi3cpp,其中定义了用于表示日期的类 Date,但类 Date的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义私有成员变量year、month、day,分别表示年、月、 日,类型为 int。请在注释*1*后添加适当的语句。 (2)完成构造函数,分别给 year、month、day 赋值,请在注释*2*后添加适当的语句。 (3)完成重载符号“+=”的定义,请在注释*3*后添加适当的语句。 (4)完成 print()打印函数,如 2008 年 8 月 8 日到屏幕和文件 modi3txt 格式相同,请在注

7、释*4*后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数 main 与其他函数中的任何内容。#includeiostreamh#includefstream#includeiomanip#includecmathusing namespace std;void WriteFile(int c) ofstream out1; out1open(“modi3txt“,ios_base:app); out1c ; out1Close();void WriteFile(char* str) Ofstream out1; out1open(“modi3txt“,ios_base:app

8、); out1Str;out1close();void ClearFile() ofstream out1; out1open(“modi3txt“);out1Close();Class Datepublic: Date(int y,int m,int d) *2* void print()const; *3* month+=m; int i=month12; int j=month12; if(j=0) year+=(i-1); month=12; elase year+=i; month=j; return *this; private: *1*;void Date:print()cons

9、t *4* WriteFile(year); WriteFile(“年“); WriteFile(month); WriteFile(“月“); WriteFile(day); WriteFile(“日“);int main() ClearFile(); Date Oly day(2008,8,8); Oly_day+=3; Oly_dayprint(); return 0;(分数:2.00)_正确答案:(正确答案:(1)添加语句:int year,month,day; (2)添加语句:year=y;month=m;day=d; (3)添加语句:Date&operator+=(int m) (

10、4)添加语句:coutyear“年“month“月“day“日“end1;)解析:解析:(1)题目 1 要求“定义私有成员变量 year、month、day”。在 C+程序的 private 区域中添加变量 year、month、day 的定义,即在第 1 个标识下添加“int year,month,day;”。 (2)题目 2 要求“完成构造函数,分别给 year、month、day 赋值”。在程序中“Date(int y,int m,int d)”的构造函数中添加给 year、month、day 赋值的语句,即在第 2 个标识下添加“year=y;month=m;day=d;”。 (3)题目 3 要求“完成重载符号“+=”的定义”。在 C+中,运算符重载的定义方法是定义一个重载运算符的函数,格式为函数 operator+重载运算符号+,所以这里补全“Date&operator+=(int m)”。 (4)题目 4 要求“完成函数 print()打印函数”。在 C+中的 print()函数中补全其打印功能,即在第四个标识下添加“coutyear“年“month“月“day“日“end1;”。

展开阅读全文
相关资源
猜你喜欢
  • AECMA PREN 2158-3-1979 MJ Threads Part 3 - Tolerances and Limiting Dimensions Aerospace Series Edition 1《MJ螺纹.第3部分 公差和极限尺寸 航空航天系列.第.第1版》.pdf AECMA PREN 2158-3-1979 MJ Threads Part 3 - Tolerances and Limiting Dimensions Aerospace Series Edition 1《MJ螺纹.第3部分 公差和极限尺寸 航空航天系列.第.第1版》.pdf
  • AECMA PREN 2159-1977 Steel FE-PM44 Hardened and Tempered Bars D Less Than or Equal to 150 mm Aerospace Series Edition 1《航空航天系列.FE-PM44淬火 调节钢板材直径D小于或等于150mm.第1版》.pdf AECMA PREN 2159-1977 Steel FE-PM44 Hardened and Tempered Bars D Less Than or Equal to 150 mm Aerospace Series Edition 1《航空航天系列.FE-PM44淬火 调节钢板材直径D小于或等于150mm.第1版》.pdf
  • AECMA PREN 2160-1985 Aerospace Series Flexible Wire Ropes for Aircraft Controls in Zinc Coated Carbon Steel Construction - Dimensions - Loads Edition 2《航空航天系列.飞机控制镀锌碳钢板构造软电缆尺寸和承重2版.pdf AECMA PREN 2160-1985 Aerospace Series Flexible Wire Ropes for Aircraft Controls in Zinc Coated Carbon Steel Construction - Dimensions - Loads Edition 2《航空航天系列.飞机控制镀锌碳钢板构造软电缆尺寸和承重2版.pdf
  • AECMA PREN 2161-1999 Aerospace Series Heat Resisting Alloy CO-CH1401 (CoCr26i11W) Not Heat Treated Precision Casting Edition P1《航空航天系列.CO-CH1401合金(CoCr26i11W)不耐热精密铸件耐热合金.P1版》.pdf AECMA PREN 2161-1999 Aerospace Series Heat Resisting Alloy CO-CH1401 (CoCr26i11W) Not Heat Treated Precision Casting Edition P1《航空航天系列.CO-CH1401合金(CoCr26i11W)不耐热精密铸件耐热合金.P1版》.pdf
  • AECMA PREN 2162-1995 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Bars Aerospace Series Edition 2 [Refer To ASD-STAN PREN 2164 ASD-STAN PREN 4246]《航空航天系列.耐热钴基 CO-C92-HT合金退火棒.pdf AECMA PREN 2162-1995 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Bars Aerospace Series Edition 2 [Refer To ASD-STAN PREN 2164 ASD-STAN PREN 4246]《航空航天系列.耐热钴基 CO-C92-HT合金退火棒.pdf
  • AECMA PREN 2163-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Forgings Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4566]《航空航天系列.耐热钴基CO-P92-HT合金退火锻造2版》.pdf AECMA PREN 2163-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Forgings Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4566]《航空航天系列.耐热钴基CO-P92-HT合金退火锻造2版》.pdf
  • AECMA PREN 2164-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Bars and Sections for Welded Rings Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4567]《航空航天系列.耐热钴基CO-P.pdf AECMA PREN 2164-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Bars and Sections for Welded Rings Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4567]《航空航天系列.耐热钴基CO-P.pdf
  • AECMA PREN 2165-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Sheets and Strips a Less Than or Equal to 3 mm Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4568]《航空航.pdf AECMA PREN 2165-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Sheets and Strips a Less Than or Equal to 3 mm Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4568]《航空航.pdf
  • AECMA PREN 2166-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Bars and Wires D Less Than or Equal to 4 mm Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4569]《航空航天系列.pdf AECMA PREN 2166-1999 Heat Resisting Cobalt Base Alloy CO-P92-HT Annealed Bars and Wires D Less Than or Equal to 4 mm Aerospace Series Edition 2 [Refer To ASD-STAN PREN 4569]《航空航天系列.pdf
  • 相关搜索

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

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