C++编程思想 答案 第五章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 5)..doc

上传人:11****ws 文档编号:3179981 上传时间:2019-05-24 格式:DOC 页数:23 大小:116KB
下载 相关 举报
C++编程思想 答案 第五章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 5)..doc_第1页
第1页 / 共23页
C++编程思想 答案 第五章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 5)..doc_第2页
第2页 / 共23页
C++编程思想 答案 第五章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 5)..doc_第3页
第3页 / 共23页
C++编程思想 答案 第五章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 5)..doc_第4页
第4页 / 共23页
C++编程思想 答案 第五章 其他章节请点击用户名找 thinking in C++ annotated solution guide(charpter 5)..doc_第5页
第5页 / 共23页
点击查看更多>>
资源描述

1、 Viewing Hints Book Home Page Free Newsletter Seminars Seminars on CD ROM Consulting Annotated Solution GuideRevision 1.0for Thinking in C+, 2nd edition, Volume 1by Chuck Allison2001 MindView, Inc. All Rights Reserved. Previous Chapter Table of Contents Next Chapter Chapter 55-1Create a class with p

2、ublic, private, and protected data members and function members. Create an object of this class and see what kind of compiler messages you get when you try to access all the class members.(Left to the reader)5-2Write a struct called Lib that contains three string objects a, b, and c. In main( ) crea

3、te a Lib object called xand assign to x.a, x.b, and x.c. Print out the values. Now replace a, b, and c with an array of string s3. Show that your code in main( ) breaks as a result of the change. Now create a class called Libc, with private string objects a, b, and c, and member functions seta( ), g

4、eta( ), setb( ), getb( ), setc( ), and getc( ) to set and get the values. Write main( ) as before. Now change the private string objects a, b, and c to a privatearray of string s3. Show that the code in main( ) does not break as a result of the change.(Left to the reader)5-3Create a class and a glob

5、al friend function that manipulates the private data in the class.(Left to the reader)5-4Write two classes, each of which has a member function that takes a pointer to an object of the other class. Create instances of both objects in main( ) and call the aforementioned member function in each class.

6、Solution:/: S05:PointToMeAndYou.cpp#include using namespace std;class You; / Forward declarationclass Me public:void ProcessYou(You* p) cout using namespace std;class HasStuff; / Must precede GoodFriend definitionclass GoodFriend / Must precede HasStuff definitionpublic:void hasAccess(HasStuff* p);v

7、oid hasNoAccess(HasStuff* p) cout x x = 5;void queryFriend(HasStuff* p) cout x using namespace std;class Hen public:void display() cout using namespace std;class Hen public:class Nest int x;friend class Hen;public:class Egg int y;friend class Nest;public: void display() cout y = 2;void display() cout x = 1;void display()

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 精品笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。