【计算机类职业资格】国家二级C++机试(操作题)模拟试卷308及答案解析.doc
《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷308及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】国家二级C++机试(操作题)模拟试卷308及答案解析.doc(3页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级 C+机试(操作题)模拟试卷 308及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6打开考生文件夹下的源程序文件 modi1cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: This is a greart! Hello Hello 注意:错误的语句在*error*的下面,修改该语句即可。#includeiostreamhclass CMyClasspublic: void displayl() cout“This is great!“endl; void display2() *error* char
2、str5=“Hello“; coutstrendl; ) *error* void display3(char string) *error* coutstringendl ;void main() CMyClass myclass; myclassdisplayl(); myclassdisplay2(); myclassdisplay3(“Hello“);(分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.使用 VC6打开考生文件夹下的源程序文件 modi2cpp。阅读下列函数说明和代码,完成空出部分程序。函数 sum(int ANUMNUM,int n)实现的功能是计算矩
3、阵中所有非质数数字的和。 提示:函数isPrime(int n)的功能是判定当前数字是否为质数,如果是则返回 true。 注意:不能修改程序的其他部分,只能修改 sum()函数。#includeiostreamh#includecmath#define NUM 50int ANUMNUM= 10,13,59,70,6, 2,40,89,92,9, 14,55,71,11,19, 79,68,83,97,101, 102,10001,23,45;bool isPrime(int n) if(n=1) return false; if(n=2) return true; for(int i=2;i
4、n2;i+) if(ni=0) return false; return true;int sum(int ANUMNUM,int n)int main() coutsum(A,5)endl; return 0;(分数:2.00)_三、综合应用题(总题数:1,分数:2.00)3.使用 VC6打开考生文件夹下的源程序文件 modi3cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义私有数据成员 year、month、day,分别用于年、月、日,它们都是 int型的数据,请在注释*1*后添加适当的语句。 (2)完成判断数据成员 date2是否是闰年函数 intDat
5、e:IsLeapYear0 的定义,返回数据成员 date2是否是闰年的值,是则返回 1,否则返回0。请在注释*2*后添加适当的语句。 (3)设置 SetData0的默认时间为:2004-12-1,请在注释*3*后添加适当的语句。 (4)完成主函数 main(),完成输出 date2 is aleapyear,请在注释*4*后添加适当的语句。 提示:公元纪年的年数可以被四整除,即为闰年;被 100整除而不能被 400整除为平年;被 100整除也可被 400整除的为闰年。 注意:增加或修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。#includeiostreamusing name
6、space std;Class Datepublic: *3* void SetDate(int y,intm,int n); int IsLeapYear(); Void Print() coutyear“-“month “-“ dayendl;Prlvate: *1*;void Date:SetDate(int y,intm,int d) year=y; month=m; day=d;int Date:IsLeapYear() *2* retUrn int main() Date datel , date2; datelSetDate(); date2SetDate(2004,12,1);
7、 cout“datel:“; datelPrint(); cout“date2:“; date2Print(); *4* Cout “date2 is“ “:“not“)“a leapyear“endl; return 0;(分数:2.00)_国家二级 C+机试(操作题)模拟试卷 308答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6打开考生文件夹下的源程序文件 modi1cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为: This is a greart! Hello Hello 注意:错误的语句在*error*的
8、下面,修改该语句即可。#includeiostreamhclass CMyClasspublic: void displayl() cout“This is great!“endl; void display2() *error* char str5=“Hello“; coutstrendl; ) *error* void display3(char string) *error* coutstringendl ;void main() CMyClass myclass; myclassdisplayl(); myclassdisplay2(); myclassdisplay3(“Hello“
9、);(分数:2.00)_正确答案:(正确答案:(1)char str6=“Hello“; 或 char str=“Hello“; (2)void display3(char*string) 或 void display3(char string) (3)coutstringendl;)解析:解析:(1)“Hello“字符串的长度为 5,存放在字符数组中的话,字符数组的长度至少为 6,因为字符数组的最后一个字符为 NULL,故第 1个标识下字符数组长度为 5太短,应改成“char str6=“Hello“;”或“char str1=“Hello“;”。 (2)char string 表示 str
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 国家 二级 机试 操作 模拟 试卷 308 答案 解析 DOC
