StringCollection
class from Project 2.
Make corrections and
improvements as needed. Test your class thoroughly before proceeding.
(You do not have to turn in your test program.)
bool
type, change your
StringCollection
class
so that boolean functions have return type bool
rather than int
.
StringCollection.H
,
add it now. Keep all documentation updated as
you continue to make changes to the StringCollection
class.
StringCollection.H
:
_array
from
String *
to const String **
. Now
_array
will ultimately point to an array of pointers
to const String
's. Why include the const
?
We are changing StringCollection
from a collection
of String
objects to a collection of pointers to
String
objects. Qualifying these pointers as
pointers to const
objects will ensure that the
String
objects being "managed" by the container
class (StringCollection
) are not going to be changed.
Add()
function so that its parameter
is of type const String *
instead of
const String &
.
Contains()
function so that instead of
simply returning true
or false
, it
returns -1 for not found, or otherwise returns the array index
where a match is found.
Quicksort()
,
Exchange()
, and Partition()
functions,
you may also need to revise their declarations.
Display
function that
accepts an int
parameter. This version of
Display()
will show a single item in the collection
rather than the entire collection. The integer specified as the
parameter is interpreted as the array index of the item to be
displayed. The function should print an appropriate message
and terminate the program if the integer is less than zero or
greater than (_count - 1)
.
friend ostream& operator << (ostream& os, const StringCollection& coll);
StringCollection.C
, make all necessary modifications to
implement the changes in the StringCollection
class outlined
above. (The basic structure of the code will stay the same, but you will
have to use pointers and indirection in many places.) Implement
Display()
and <<
as follows:
Display()
with no arguments should loop through
the array of base class (String
) pointers and call
Display()
through each pointer in the array.
Display()
with an integer argument should call
Display()
through the appropriate pointer in the
array of pointers.
<<
operator should not call Display()
. Instead
it should use the <<
operator. This will allow
us to demonstrate that dynamic binding can be made to work even when
non-member functions are involved. (Remember that the insertion
and extraction operators are always written as non-member functions.)
StringCollection
class using the
String
class from Project 4. You should be able to adapt
your main()
from Proj2.C
to use as a test program.
StringCollection
class
also work for IString
objects, as well as objects of any
future class derived from String
. Add the keyword
virtual
in two places in String.H
: the declaration
for Display()
and the declaration for the destructor.
StringCollection
class again using some
IString
objects. It should also work if it contains a
mixture of String
and IString
objects.
main()
in a file called
Proj5.C
:
The name of your executable must be Proj5.