JMU
../DukeDisc.gif
DukeDisc v3


Background
Changes to Existing Code:
The DiscChanger Class: You must write a DiscChanger class that must be in the v3 subdirectory. This class must have the same functionality as version 2, except:
  • The size variable must not be "hard coded" to a particular value.
  • The array of 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).
  • It must dynamically allocate memory for the array of Slot objects.
  • It must have an explicit value constructor that is passed an int containing the number of slots in the DiscChanger.
  • It must have a default constructor. The default size of a DiscChanger must be 6.
  • It must have a destructor that behaves appropriately.
The Driver: You must write a driver named 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!

Other Issues:
Code Duplication: Remember you should not have duplicate code in different constructors. Also remember that one constructor cannot call another. So, if you have common construction tasks you should create a private method that performs them and is called by the different constructors.
Building: The following 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.

Testing: You can use the same tests you used for v1.

Copyright 2010