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

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

1、国家二级 C+机试(操作题)-试卷 160 及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6 打开考生文件夹下的源程序文件 modi1cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为:Hello 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在*error*的下面。#includeiostreamhvoid main()*error*typedef BOOL bool;*error*BOOL a=FALSE;int i=0X80000000;*error*a=!i;

2、if(a)cout“Hello“endl;return;(分数:2.00)_二、简单应用题(总题数:1,分数:2.00)2.使用 VC6 打开考生文件夹下的源程序文件 modi2cpp。阅读下列函数说明和 C 代码,完成空出部分的程序,实现函数 fun(char*s1,char*s2)将字符串 s2 连接在字符串 s1 之后,构成一个首指针为 s1 的字符串。注意:不能修改函数的其他部分。#includeiostreamh#define MAXLINE1000void fun(char*s1,char*s2)void main()char s1NAXLINE;char s2256;cout“p

3、lease input a string:“endl;cingetline(s1,NAXLINE);Cout“please input otherstring:“endl;cingetline(s2,256);fun(s1,s2);couts1endl;return;(分数:2.00)_三、综合应用题(总题数:1,分数:2.00)3.使用 VC6 打开考生文件夹下的源程序文件 modi3cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。(1)完成构造函数的定义,请在注释*1*后添加适当的语句。(2)定义类的友元函数 fun(),请在注释*2*后添加适当的语句。(3)定义类的

4、友元函数main(),请在注释*3*后添加适当的语句。(4)补充语句,释放内存。请在注释*4*后添加适当的语句。注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。#includeiostreamhclass TestClasspublic:*1*data=d;next=NULL;void SetNext(TestClass* p)next=p;private:int data;TestClass* next;*2*3*;TestClass* fun(TestClass* h)TestClasS *t,*s,*u,*v;s=h-next;h-next=NULL;while(s!=NUL

5、L)for(t=s,v=h;v!=NULL&v-datat-data;u=v,v=v-next);s=s-next;if(v=h)h=t;elseu-next=v;t-next=v;return h;void main()TestClass* h=NULL;TestClass* q=NULL;doint data;cout“please input a number,and end with0“endl;cindata;if(data=0)break;TestClass* p=newTestClass(data);if(h=NULL)h=q=p;elseq-SetNext(p);q=p;whi

6、le(1);h=fun(h);for(;h!=NULL;)q=h-next;couth-data“ “endl;delete h;*4*return;(分数:2.00)_国家二级 C+机试(操作题)-试卷 160 答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6 打开考生文件夹下的源程序文件 modi1cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为:Hello 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在*error*的下面。#includeiostreamhv

7、oid main()*error*typedef BOOL bool;*error*BOOL a=FALSE;int i=0X80000000;*error*a=!i;if(a)cout“Hello“endl;return;(分数:2.00)_正确答案:(正确答案:(1)typedef bool BOOL; (2)BOOL a=false; (3)a=(i!=0);)解析:解析:(1)第 1 个标识下的“typedef BOOL bool;”。typedef 为 C 语言的关键字,作用是为一种数据类型定义一个新名字。一般形式应该是:typedef 标准数据类型新的数据类型名,所以第 1 个标识

8、下应该是“typedefbool BOOL;”。 (2)C+中逻辑假的值应该是 false 而不是 FALSE,所以这里修改为“BOOLa=fatse;”。 (3)题目要求输出 Hello,它要在“if(a)”为真的时候输出“Hello”。i 的值为0X80000000,第 3 个标识下 a=!i;语句中 a 的值为假。i!=0 为真,所以修改为“a=(if=0);”。二、简单应用题(总题数:1,分数:2.00)2.使用 VC6 打开考生文件夹下的源程序文件 modi2cpp。阅读下列函数说明和 C 代码,完成空出部分的程序,实现函数 fun(char*s1,char*s2)将字符串 s2 连

9、接在字符串 s1 之后,构成一个首指针为 s1 的字符串。注意:不能修改函数的其他部分。#includeiostreamh#define MAXLINE1000void fun(char*s1,char*s2)void main()char s1NAXLINE;char s2256;cout“please input a string:“endl;cingetline(s1,NAXLINE);Cout“please input otherstring:“endl;cingetline(s2,256);fun(s1,s2);couts1endl;return;(分数:2.00)_正确答案:(正确

10、答案:int i=0; for(i=0;s1i!=0;i+);指向第一个串尾 for(int j=0;s2j!=0;j+)利用循环将第二个串拷贝到第一个串尾 s1i+=s2j; s1i=0,加尾符)解析:解析:(1)首先利用循环指向第一个串尾。 (2)然后利用 for 循环将第二个串连接到第一个串尾。 (3)最后在新生成的串尾加尾符号。三、综合应用题(总题数:1,分数:2.00)3.使用 VC6 打开考生文件夹下的源程序文件 modi3cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。(1)完成构造函数的定义,请在注释*1*后添加适当的语句。(2)定义类的友元函数 fun(

11、),请在注释*2*后添加适当的语句。(3)定义类的友元函数main(),请在注释*3*后添加适当的语句。(4)补充语句,释放内存。请在注释*4*后添加适当的语句。注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。#includeiostreamhclass TestClasspublic:*1*data=d;next=NULL;void SetNext(TestClass* p)next=p;private:int data;TestClass* next;*2*3*;TestClass* fun(TestClass* h)TestClasS *t,*s,*u,*v;s=h-next

12、h-next=NULL;while(s!=NULL)for(t=s,v=h;v!=NULL&v-datat-data;u=v,v=v-next);s=s-next;if(v=h)h=t;elseu-next=v;t-next=v;return h;void main()TestClass* h=NULL;TestClass* q=NULL;doint data;cout“please input a number,and end with0“endl;cindata;if(data=0)break;TestClass* p=newTestClass(data);if(h=NULL)h=q=p

13、elseq-SetNext(p);q=p;while(1);h=fun(h);for(;h!=NULL;)q=h-next;couth-data“ “endl;delete h;*4*return;(分数:2.00)_正确答案:(正确答案:(1)添加语句:TestClass(int d) (2)添加语句:friend TestClass* fun(TestClass*); (3)添加语句:friend void main(); (4)添加语句:h=q;)解析:解析:(1)题目 1 要求“完成构造函数的定义”。构造函数是一种特殊的成员函数,它的名字必须与类同名,所以这里的构造函数名字是 Tes

14、tClass。根据构造函数内的“data=d;”语句,知道构造函数TestClass 中参数 d 为 int 型,即这里补全“TestClass(int d)”。 (2)题目 2 要求“定义类的友元函数fun()”。在 C+中,如果在本类以外的其它地方定义了一个函数,在类体中是用 friend 对该函数进行声明的,此函数称为本类的友元函数,并且能够调用本类中的成员变量。程序中 fun()在类 TestClass 以外的地方定义的,为了其实现对类 TestClass 中程序变量的调用,在类 TestClass 中补全“friend TestClass*fun(TestClass*);”。 (3)题目 3 要求“定义类的友元函数 main()。”同(2),这里补全“friend void main();”。 (4)题目 4 要求“补充语句,释放内存。”为了防止内存泄漏,在指针使用后要将其释放。第四个标识前面的“delete h;”语句已经将指针 h 释放了,所以要释放指针 q,只要将其指向 h 就可以了,即“h=q;”。

展开阅读全文
相关资源
猜你喜欢
  • DIN 10194-1987 Microbiological analysis of milk detection of Streptococcus agalactiae in untreated milk《牛奶的微生物分析 未加工的牛奶中连球菌的监测》.pdf DIN 10194-1987 Microbiological analysis of milk detection of Streptococcus agalactiae in untreated milk《牛奶的微生物分析 未加工的牛奶中连球菌的监测》.pdf
  • DIN 10197-1988 Microbiological analysis of milk detection of staphylococcal thermonuclease reference method《牛奶的微生物检验 葡萄球菌热核反应的检定 参考法》.pdf DIN 10197-1988 Microbiological analysis of milk detection of staphylococcal thermonuclease reference method《牛奶的微生物检验 葡萄球菌热核反应的检定 参考法》.pdf
  • DIN 10198-2010 Microbiological analysis of milk - Determination of presumptive Bacillus cereus - Colony count technique at 37 C《牛奶的微生物检验 推测的蜡样芽孢杆菌的测定 37℃菌落计数技术》.pdf DIN 10198-2010 Microbiological analysis of milk - Determination of presumptive Bacillus cereus - Colony count technique at 37 C《牛奶的微生物检验 推测的蜡样芽孢杆菌的测定 37℃菌落计数技术》.pdf
  • DIN 1022-2004 Steel bars - Hot-rolled square root equal angles (LS-steel) - Dimensions masses and tolerances《钢棒 热轧方形底部等边角钢(LS 钢) 尺寸、重量和公差》.pdf DIN 1022-2004 Steel bars - Hot-rolled square root equal angles (LS-steel) - Dimensions masses and tolerances《钢棒 热轧方形底部等边角钢(LS 钢) 尺寸、重量和公差》.pdf
  • DIN 10223-1996 Analysis of spices and condiments - Determination of total ash and acid-insoluble ash《香料和调料分析 全部灰分和酸不溶灰分的测定》.pdf DIN 10223-1996 Analysis of spices and condiments - Determination of total ash and acid-insoluble ash《香料和调料分析 全部灰分和酸不溶灰分的测定》.pdf
  • DIN 10229-2000 Analysis of spices and condiments - Determination of moisture content - Entrainment method《香料和调味品的分析 水分含量的测定 雾沫法》.pdf DIN 10229-2000 Analysis of spices and condiments - Determination of moisture content - Entrainment method《香料和调味品的分析 水分含量的测定 雾沫法》.pdf
  • DIN 10234-2003 Analysis of spices and condiments - Determination of capsaicinoid content of powdered paprika paprika oleoresins powdered chillies and chillie oleoresins - Method us).pdf DIN 10234-2003 Analysis of spices and condiments - Determination of capsaicinoid content of powdered paprika paprika oleoresins powdered chillies and chillie oleoresins - Method us).pdf
  • DIN 10235-1999 Pepper an pepper oleoresins - Determination of piperine content - Method using high-performance liquid chromatography (HPLC)《胡椒和胡椒油树脂 胡椒碱含量的测定 高效液相色谱法》.pdf DIN 10235-1999 Pepper an pepper oleoresins - Determination of piperine content - Method using high-performance liquid chromatography (HPLC)《胡椒和胡椒油树脂 胡椒碱含量的测定 高效液相色谱法》.pdf
  • DIN 10236-2001 Analysis of spices and condiments - Determination of loss in mass of capsicum and allium species and of dried vegetables by vacuum oven drying《香料和调味品分析 真空炉干燥法测定辣椒和洋葱.pdf DIN 10236-2001 Analysis of spices and condiments - Determination of loss in mass of capsicum and allium species and of dried vegetables by vacuum oven drying《香料和调味品分析 真空炉干燥法测定辣椒和洋葱.pdf
  • 相关搜索

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

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