[计算机类试卷]国家二级C++机试(操作题)模拟试卷98及答案与解析.doc

上传人:bowdiet140 文档编号:497660 上传时间:2018-11-28 格式:DOC 页数:8 大小:34KB
下载 相关 举报
[计算机类试卷]国家二级C++机试(操作题)模拟试卷98及答案与解析.doc_第1页
第1页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷98及答案与解析.doc_第2页
第2页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷98及答案与解析.doc_第3页
第3页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷98及答案与解析.doc_第4页
第4页 / 共8页
[计算机类试卷]国家二级C++机试(操作题)模拟试卷98及答案与解析.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

1、国家二级 C+机试(操作题)模拟试卷 98及答案与解析 一、基本操作题 1 使用 VC6打开考生文件夹下的源程序文件 modil cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为: 1 1 2 1 注意:不要改动 main函数,不能增行或删行,也不能更改程序的结构,错误的语句在 *error*的下面。 #include C1ass TestClasS *error* *error* const int j; public: TestClasS() *error* statiC int i=0 ; cout void MergeAndSort(int s, in

2、t e, int a, int m, int n) int main() int data2 0, i ; int a=1, 3, 5, 6); int b=2, 4, 5, 7, 11, 13); cout C1ass TestClass public: *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一 n

3、ext=NULL; while(s!=NULL) for(t=s, v=h; v!=NULL else U一 next=V; t一 next=v; return h; void main() TestClass*h=NULL; TestClass*q=NULL; do int data; coutdata; if(data=0)break; TestClass*P = new TestClasS(data); if(h=NULL) h=q=P; else q一 SetNext(P); q=P; while(1); h=fun(h); for(; h!=NULL ;) q=h一 next; co

4、utdataaj,取小 的 aj Sk+ =aJ+; while( im) sk+ =ei+; 如果数组 e后面还有没有加进来的元素,则加进去 while(jn) sk+ =aj+;如果数组 a后面还有没有加进来的元素,则加进去 【试题解析】 (1)由审题分析可知,可设置循环来逐个读取 e数组和 a数 组的元素值,然后选择小的元素放在数组 s中,如果相等则取 a数组元素或 e数组元素均可,可以利用 ifelse语句来进行判断。 (2)由于数组 e和数组 a长度可能不一定相同,因此在循环结束之后,还需要把长度长的数组的剩余的元素添加到 s数字中,即循环结束后如果 e数组内还有字符的话把 e数组内

5、剩下的字符添加到 s数组内,同样如果 a数组内还有字符的话把 a数组内剩下的字符添加到 S数组内。 三、综合应用题 3 【正确答案】 (1)添加语句: TestClass(intd) (2)添加语句: friend TestC3 ass*fun(TestClass*); (3)添加语句: friend void mein(); (4)添加语句: h=q; 【试题解析】 本题的功能是将键盘输入的数字建立一个链表。在 VC环境下打开程序,根据题干给出的几条功能要求,对程序中给出注释下的内容逐个补全或修改。从已定源程序的 main主函数开始入手,可以看出程序通过调用类 lestClass和函数 fu

6、n实现各种输出操作。 【解题思路】 (1)题目 1要求 “完成构造函数的定义 ”。构造函数是一种特殊的成员函数,它的名字必须与类同名,所以这里的构造函数 名字是 TestClass。根据构造函数内的“data=d; “语句,知道构造函数 TestClass中参数 d为 int型,即这里补全“TestClass(intd)”。 (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; ”。

展开阅读全文
相关资源
猜你喜欢
  • STAS SR ISO 1171-1981 Solid mineral fuels Determination of asn《固体矿物燃料.灰分的测定 》.pdf STAS SR ISO 1171-1981 Solid mineral fuels Determination of asn《固体矿物燃料.灰分的测定 》.pdf
  • STAS SR ISO 1178-1995 Magnesium alloys Determination of soluble zirconium Alizarin sulphonate photometric method《镁合金.测定可溶性锆.茜素磺酸光度法》.pdf STAS SR ISO 1178-1995 Magnesium alloys Determination of soluble zirconium Alizarin sulphonate photometric method《镁合金.测定可溶性锆.茜素磺酸光度法》.pdf
  • STAS SR ISO 1183-1994 Plastics - Methods for determining the density and relative density of non-cellular plastics《塑料.确定非泡沫塑料密度和相对密度的方法 》.pdf STAS SR ISO 1183-1994 Plastics - Methods for determining the density and relative density of non-cellular plastics《塑料.确定非泡沫塑料密度和相对密度的方法 》.pdf
  • STAS SR ISO 1187-1996 Special wrought copper alloys Chemical composition and forms of wrought products《特殊锻造铜合金.化学成分和锻造产品的各种形式》.pdf STAS SR ISO 1187-1996 Special wrought copper alloys Chemical composition and forms of wrought products《特殊锻造铜合金.化学成分和锻造产品的各种形式》.pdf
  • STAS SR ISO 1190 1-1993 Cooper and cooper alloys - Code of designation - Part 1  Designntinn of materials《铜与铜合金.代码的指定.第1部分: 材料的指定》.pdf STAS SR ISO 1190 1-1993 Cooper and cooper alloys - Code of designation - Part 1 Designntinn of materials《铜与铜合金.代码的指定.第1部分: 材料的指定》.pdf
  • STAS SR ISO 1190 2-1993 Copper and copper alloys Code of designation Part 2  Designation of tempers《铜及其合金.标志代码.第2部分:回火标识》.pdf STAS SR ISO 1190 2-1993 Copper and copper alloys Code of designation Part 2 Designation of tempers《铜及其合金.标志代码.第2部分:回火标识》.pdf
  • STAS SR ISO 1204-1990 Reciprocating internai combustion engines - Designation of the direction of rotation and of cylinders and valves in cylinder heads and definition of right-hana.pdf STAS SR ISO 1204-1990 Reciprocating internai combustion engines - Designation of the direction of rotation and of cylinders and valves in cylinder heads and definition of right-hana.pdf
  • STAS SR ISO 1210-1993 Plastics Determination of flammability characteristics of plastics in the form of small specimens in contact with a small flame《塑料.与小火焰相接触的小试样硬质塑料易燃特性的测定》.pdf STAS SR ISO 1210-1993 Plastics Determination of flammability characteristics of plastics in the form of small specimens in contact with a small flame《塑料.与小火焰相接触的小试样硬质塑料易燃特性的测定》.pdf
  • STAS SR ISO 1213-1-1995 Solid mineral fuels Vocabulary Part 1  Terms relating to coal preparation《固体矿物燃料.词汇.第1部分:煤制备有关的术语》.pdf STAS SR ISO 1213-1-1995 Solid mineral fuels Vocabulary Part 1 Terms relating to coal preparation《固体矿物燃料.词汇.第1部分:煤制备有关的术语》.pdf
  • 相关搜索

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

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