Description
A DiscChanger
is an encapsulation of a CD/DVD multi-disc
changer. It is a circular collection of Slot
objects.
At any point in time, exactly one Slot
can be considered
"currently selected" (i.e., there is one Slot
that can be
ejected, loaded, etc...).
A DiscChanger
must keep track of two things:
Slot
.Methods
This class must contain the following public methods. It may contain other methods as well.
Default Constructor:
DiscChanger
.
When first initialized, the "power" should be off (see the discussion
of the on()
and off()
methods below).
The eject Method:
eject
that has no parameters and does not return anything.
This method must clear the "currently selected" Slot
.
The ejectAll Method:
ejectAll
that has no parameters and does not return anything.
This method must clear all of the Slot
objects, starting
with the "currently selected" Slot
.
The getID Method:
getID
that is passed an int
by reference and
does not return anything. This method must set the value of the
int
parameter to the ID of the disc that
is currently in this Slot
. (When it is empty, the ID
must be set to 0.)
The loadDisc Method:
loadDisc
that is passed an int
by value and
does not return anything. If (and only if)
the "currently selected" Slot
is empty, this method must store the
int
it is passed in an attribute of the Slot
.
The next Method:
next
that has no parameters and does not return anything.
This method must change the "currently selected" Slot
to the
next Slot
in the collection.
Since the collection of Slot
objects is circular,
if the DiscChanger
has N slots, calling the
next
method N times in a row should bring
the DiscChanger
back to the Slot
at which it started.
The off Method:
off
that has no parameters and does not return anything.
After the off
method is called the DiscChanger
must ignore all subsequent method calls until the
on
method is called.
The on Method:
on
that has no parameters and does not return anything.
This method effectively turns the DiscChanger
on.
That is, it instructs the DiscChanger
to stop ignoring method calls.
The previous Method:
previous
that has no parameters and does not return anything.
This method must change the "currently selected" Slot
to the
previous Slot
in the collection.
Since the collection of Slot
objects is circular,
if the DiscChanger
has N slots, calling the
previous
method N times in a row should bring
the DiscChanger
back to the Slot
at which it started.
Additional Requirements
This class must satisfy the following additional requirements:
The on and off Methods:
on
and off
methods effectively turn the
system on and off. In other words,
when a DiscChanger
is off it must ignore all method calls
other than calls to the on
method.
The Currently Selected Slot:
next
and previous
may permanently change the "currently selected" slot.
That is, the "currently selected" slot after the method completes
must be the same as the "currently selected" slot when the
method is called.
The Size of the DiscChanger
The size of the DiscChanger
(i.e., the number of
Slot
objects in the collection) must be set at compile time
and the memory for the collection must be allocated at compile time.
However, you must be able to change the size (when compiling) without editing
either the .h
or the .cpp
file.
To achieve these ends you must use the preprocessor's #define
directive. Specifically, you must include the following at the
top of the .h
file:
#ifndef SIZE #define SIZE 6 #endif
Then, you must use the symbol SIZE
when declaring/creating
the collecton of Slot
objects.
When compiling any class that uses the DiscChanger
class
(i.e., any class that #include
s
DiscChanger.h
) you can use the -D
flag to
define the SIZE
symbol (and, in effect, override the
default size of 6). For example:
g++ -c -DSIZE=10 DiscChanger.cpp
would set the size of the collection to 10.
Copyright 2010