DiscChanger
is given its size at run time and allocates memory
for the Slot
objects dynamically (i.e., from the
memory heap/free store).
DiscChanger
class that must be in the
v3
subdirectory. This class must have the same functionality
as version 2, except:
size
variable must not be "hard coded"
to a particular value.Slot
objects must not be "hard coded"
in the header file. Instead, the header should declare
a pointer to a Slot
(that will actually point
to an array of Slot
objects).Slot
objects.int
containing the number of slots
in the DiscChanger
.DiscChanger
must be 6.Driver3.cpp
(that must be in the DukeDisc
directory).
The only difference between this driver and Driver2.cpp
is that it must pass a (hard-coded) size to the
DiscChanger
constructor.
Since the driver uses both the DiscChanger
and
TextInterface
classes it must #include
the appropriate header files. In this case the preprocessor
statements must be:
// THE ORDER MATTERS!!! #include "v3/DiscChanger.h" #include "v2/TextInterface.h"
As noted, the order of these two preprocessor statements is very important. Make sure you understand why!
makefile
may prove to be useful in this
regard:
# Phony target to build all versions # all: v1 v2 v3 # Phony targets for each version # v1: Driver1 v2: Driver2 v3: Driver3 # Drivers # Driver1: Driver1.o v1/DiscChanger.o v1/Slot.o g++ Driver1.o v1/DiscChanger.o v1/Slot.o -o Driver1 Driver1.o: Driver1.cpp v1/DiscChanger.h g++ -c Driver1.cpp Driver2: Driver2.o v2/TextInterface.o v1/DiscChanger.o v1/Slot.o g++ Driver2.o v2/TextInterface.o v1/DiscChanger.o v1/Slot.o -o Driver2 Driver2.o: Driver2.cpp v2/TextInterface.h v1/DiscChanger.h g++ -c Driver2.cpp Driver3: Driver3.o v2/TextInterface.o v3/DiscChanger.o v1/Slot.o g++ Driver3.o v2/TextInterface.o v3/DiscChanger.o v1/Slot.o -o Driver3 Driver3.o: Driver3.cpp v2/TextInterface.h v3/DiscChanger.h g++ -c Driver3.cpp # v1 of DiscChanger and Slot # v1/DiscChanger.o: v1/DiscChanger.cpp v1/DiscChanger.h v1/Slot.h g++ -c v1/DiscChanger.cpp -o v1/DiscChanger.o v1/Slot.o: v1/Slot.cpp v1/Slot.h g++ -c v1/Slot.cpp -o v1/Slot.o # v2 of TextInterface # v2/TextInterface.o: v2/TextInterface.cpp v2/TextInterface.h g++ -c v2/TextInterface.cpp -o v2/TextInterface.o # v3 of DiscChanger # v3/DiscChanger.o: v3/DiscChanger.cpp v3/DiscChanger.h v1/Slot.h g++ -c v3/DiscChanger.cpp -o v3/DiscChanger.o
You can build version 3 of DukeDisc
with the command make v3
.
Copyright 2010