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

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

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

2、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 一next=NULL; while(s!=NULL) for(t=s,v=h;v!=NULL else U 一next=V; t 一next=v; return h; void main() TestClass

3、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; cout C1ass TestClass public: *1* data=d; next=NULL; void SetNext(TestClass*P) next=P ; private: int data; T

4、estClass*next; *2* *3* ; TestClass*fun(TestClass*h) TestClass *t,*s,*u,*v; S=h 一next: h 一next=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=

5、NULL) h=q=P; else q 一SetNext(P); q=P; while(1); h=fun(h); for(; h!=NULL ;) q=h 一next; coutdata”_正确答案:(正确答案:(1)添加语句:TestClass(intd) (2)添加语句:friend TestC3ass*fun(TestClass*); (3)添加语句:friend void mein(); (4)添加语句:h=q;)解析:解析:本题的功能是将键盘输入的数字建立一个链表。在 VC 环境下打开程序,根据题干给出的几条功能要求,对程序中给出注释下的内容逐个补全或修改。从已定源程序的 main

6、 主函数开始入手,可以看出程序通过调用类lestClass 和函数 fun 实现各种输出操作。 【解题思路】 (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;”。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 2240-037-2010 Aerospace series - Lamps incandescent - Part 037 Lamp code 394 - Product standard German and English version EN 2240-037 2010《航空航天系列 白炽灯 第037部分 灯 编码394 产品标准 德文.pdf DIN EN 2240-037-2010 Aerospace series - Lamps incandescent - Part 037 Lamp code 394 - Product standard German and English version EN 2240-037 2010《航空航天系列 白炽灯 第037部分 灯 编码394 产品标准 德文.pdf
  • DIN EN 2240-038-2010 Aerospace series - Lamps incandescent - Part 038 Lamp code 401 - Product standard German and English version EN 2240-038 2010《航空航天系列 白炽灯 第038部分 灯 编码401 产品标准 德文.pdf DIN EN 2240-038-2010 Aerospace series - Lamps incandescent - Part 038 Lamp code 401 - Product standard German and English version EN 2240-038 2010《航空航天系列 白炽灯 第038部分 灯 编码401 产品标准 德文.pdf
  • DIN EN 2240-039-2010 Aerospace series - Lamps incandescent - Part 039 Lamp code 600 - Product standard German and English version EN 2240-039 2010《航空航天系列 白炽灯 第039部分 灯 编码600 产品标准 德文.pdf DIN EN 2240-039-2010 Aerospace series - Lamps incandescent - Part 039 Lamp code 600 - Product standard German and English version EN 2240-039 2010《航空航天系列 白炽灯 第039部分 灯 编码600 产品标准 德文.pdf
  • DIN EN 2240-040-2010 Aerospace series - Lamps incandescent - Part 040 Lamp code 680 - Product standard German and English version EN 2240-040 2010《航空航天系列 白炽灯 第040部分 灯 编码680 产品标准 德文.pdf DIN EN 2240-040-2010 Aerospace series - Lamps incandescent - Part 040 Lamp code 680 - Product standard German and English version EN 2240-040 2010《航空航天系列 白炽灯 第040部分 灯 编码680 产品标准 德文.pdf
  • DIN EN 2240-041-2010 Aerospace series - Lamps incandescent - Part 041 Lamp code 682 - Product standard German and English version EN 2240-041 2010《航空航天系列 白炽灯 第041部分 灯 编码682 产品标准 德文.pdf DIN EN 2240-041-2010 Aerospace series - Lamps incandescent - Part 041 Lamp code 682 - Product standard German and English version EN 2240-041 2010《航空航天系列 白炽灯 第041部分 灯 编码682 产品标准 德文.pdf
  • DIN EN 2240-042-2010 Aerospace series - Lamps incandescent - Part 042 Lamp code 683 - Product standard German and English version EN 2240-042 2010《航空航天系列 白炽灯 第042部分 灯 编码683 产品标准 德文.pdf DIN EN 2240-042-2010 Aerospace series - Lamps incandescent - Part 042 Lamp code 683 - Product standard German and English version EN 2240-042 2010《航空航天系列 白炽灯 第042部分 灯 编码683 产品标准 德文.pdf
  • DIN EN 2240-043-2010 Aerospace series - Lamps incandescent - Part 043 Lamp code 685 - Product standard German and English version EN 2240-043 2010《航空航天系列 白炽灯 第043部分 灯 编码685 产品标准 德文.pdf DIN EN 2240-043-2010 Aerospace series - Lamps incandescent - Part 043 Lamp code 685 - Product standard German and English version EN 2240-043 2010《航空航天系列 白炽灯 第043部分 灯 编码685 产品标准 德文.pdf
  • DIN EN 2240-044-2010 Aerospace series - Lamps incandescent - Part 044 Lamp code 713 - Product standard German and English version EN 2240-044 2010《航空航天系列 白炽灯 第044部分 灯 编码713 产品标准 德文.pdf DIN EN 2240-044-2010 Aerospace series - Lamps incandescent - Part 044 Lamp code 713 - Product standard German and English version EN 2240-044 2010《航空航天系列 白炽灯 第044部分 灯 编码713 产品标准 德文.pdf
  • DIN EN 2240-045-2010 Aerospace series - Lamps incandescent - Part 045 Lamp code 714 - Product standard German and English version EN 2240-045 2010《航空航天系列 白炽灯 第045部分 灯 编码714 产品标准 德文.pdf DIN EN 2240-045-2010 Aerospace series - Lamps incandescent - Part 045 Lamp code 714 - Product standard German and English version EN 2240-045 2010《航空航天系列 白炽灯 第045部分 灯 编码714 产品标准 德文.pdf
  • 相关搜索

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

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