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

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

1、国家二级 C+机试(操作题)-试卷 79 及答案解析(总分:6.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:2.00)1.使用 VC6 打开考生文件夹下的源程序文件 modicpp,该程序运行时有错,请改正其中错误,使得程序正常运行,并使程序输出的结果为: c Test 注意:不要改动 main 函数,不能增行或删行,也不能更改程序的结构,错误的语句在*error*的下面。 #include void main() *error* char C=“C”; coutID:ID_umber; *1* ; ClasS CBooks private: class Node publi

2、c: Node*next; CBook*book ; *m_pBook; public: CBooks() m_pBook=NULL; CBooks() *2* while() Node*p* m pBook 一next ; delete m_pBook 一book; delete m_pBook; m_pBook=P ; int AddBookMenber(int nID,char*Author) Node*P=m_pBook; Node*q=NULL; *3* while() if(nID=P一 book 一ID) return 0, q=P ; P=P 一next ; if(P=NULL

3、) P=new Node, P 一next=NULL, P 一book =new CBook(nID,Author); if(q=NULL) m_pBook=p; else q 一next=P; return 1 ; char*GetBookAuthor (int nID) Node*P=m pBook; *4* while() if(p 一book 一ID =nID) return P 一 book-Author ; P=p 一next; return 0 ; ;int main() CBooks booksl ; books 1AddBookMenbe r (1,“Tom”); books

4、lAddBookMenber (3,“Lee”); books 1AddBookMenbe r (4,“Lily”); books 1AddBookMenber (5,“Harry”);coutID:ID_umber; *1* ; ClasS CBooks private: class Node public: Node*next; CBook*book ; *m_pBook; public: CBooks() m_pBook=NULL; CBooks() *2* while() Node*p* m pBook 一next ; delete m_pBook 一book; delete m_pB

5、ook; m_pBook=P ; int AddBookMenber(int nID,char*Author) Node*P=m_pBook; Node*q=NULL; *3* while() if(nID=P一 book 一ID) return 0, q=P ; P=P 一next ; if(P=NULL) P=new Node, P 一next=NULL, P 一book =new CBook(nID,Author); if(q=NULL) m_pBook=p; else q 一next=P; return 1 ; char*GetBookAuthor (int nID) Node*P=m

6、 pBook; *4* while() if(p 一book 一ID =nID) return P 一 book-Author ; P=p 一next; return 0 ; ;int main() CBooks booksl ; books 1AddBookMenbe r (1,“Tom”); bookslAddBookMenber (3,“Lee”); books 1AddBookMenbe r (4,“Lily”); books 1AddBookMenber (5,“Harry”);cout_正确答案:(正确答案:(1)添加语句:strcpy(Author,Author_Name); (

7、2)将“while()”补充完整为:while(m pBook!=NULL) (3)将“while()”补充完整为:while(P!=NULL) (4)将“while()”补充完整为:while(p!=NULL)解析:解析:(1)第 1 个标识下完成 CBook 类的构造函数,对成员变量整 ID 和作者 Auor 进行初始化,因此第 1 个标识下应添加“strcpy(Author,Author_Name);”,利用 strcpy 函数,将 Author Name 数组内容拷贝到 Author 数组中。 (2)CBooks0 为 CBooks 类的析构函数,由于 CBooks 类在运行过程中会动

8、态申请内存空间,因此在析构函数中必须将这些内存释放。CBooks 类是由 Node 对象组成的链表,因此可利用循环逐个搜索这个链表,逐个释放内存空间,故第 2 个标识下应改为 while(m pBook!=NULL),在 while循环体不断的搜索下一个节点直到 m pBook 为空为止,删除所以节点。 (3)AddBookMenber(int nlDchar*Author)数在链表的最后添加一个新的节点,因此必须先找到最后一个节点,同样利用循环寻找最后一个节点,故第 3 个标识下为 while(P!=NULL。 (4)GetBookAuthor(int nID)返回某个 Node 节点的 CBook 对象的 ID 为 nlD 的 CBook 对象的 Author 数组名,同样需要利用循环来查找各个节点 CBook 对象的 ID 是否为 nlD,故第 4 个标识下应为 while(p!=NULL)。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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