Create
a class with
public,
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.
Write
a
struct
called
Lib
which contains three
string
objects
a,
b
and
c.
In
main( )
create a
Lib
object called
x
and
assign to
x.a,
x.b,
and
x.c.
Print out the values. Now replace
a,
b
and
c
with an array of
string
s[3]
.
Show that your code in
main( )
breaks as a result of the change.
Now
create a
class
called
Libc,
with
privatestring
objects
a,
b
and
c,
and member functions
seta( ),
geta( ),
setb( ),
getb( ),
setc( ),
getc( )
to set and get the values. Write
main( )
as before. Now change the
privatestring
objects
a,
b
and
c
to a
private
array
of
string
s[3]
.
Show that the code in
main( )
does
not
break as a result of the change.
Create
a class and a global
friend
function that manipulates the
private
data in the class.
Write
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.
Create
three classes. The first class contains
private
data,
and grants friendship to the entire second class and to a member function of
the third class. In
main( ),
demonstrate that all these work correctly.
Create
a
Hen
class. Inside this, nest a
Nest
class. Inside
Nest,
place an
Egg
class. Each class should have a
display( )
member function. In
main( ),
create an instance of each class and call the
display( )
function for each one.
Modify
the above example so that
Nest
and
Egg
each contain
private
data. Grant friendship to allow the enclosing classes access to this
private
data.
Create
a class with data members distributed among numerous
public,
private
and
protected
sections. Add a member function
showMap( )
which prints the names of each of these data members and their addresses. If
possible, compile and run this program on more than one compiler and/or
computer and/or operating system to see if there are layout differences in the
object.
Copy
the implementation and test files for
Stash
in
the previous chapter so you can compile and test
Stash.h
in this chapter.
Place
objects of the
Hen
class from the earlier exercise in a
Stash.
Fetch them out and print them (if you have not already done so, you will need
to add
Hen::print( )).
Copy
the implementation and test files for
Stack
in
the previous chapter so you can compile and test
Stack2.h
in this chapter.
Place
objects of the
Hen
class from the earlier exercise in a
Stack.
Fetch them out and print them (if you have not already done so, you will need
to add
Hen::print( )).
Modify
Cheshire
in
Handle.cpp,
and verify that your project manager recompiles and relinks only this file, but
doesn’t recompile
UseHandle.cpp.