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()