Duration
class that
encapsulates the duration of events (e.g. telephone calls).
At a minimum, it must have two int
attributes
that are used to hold the number of minutes and seconds
in the Duration
. The seconds must be in the
interval [0, 60) and the minutes must be greater than or
equal to 0.
At a minimum it must also have the following methods:
Duration
to 0 minutes and 0 seconds).
int
values containing the minutes and
seconds (in that order).
char *toString()
method that returns a pointer
to a character array that contains a nicely-formatted
representation of a Duration
. (Note: Think carefully about
whether the memory for the character array should come from
the stack or the heap and what that means for the caller.)
At a minimum it must also have the following operators:
+
operator that adds two Duration
objects and returns a Duration
object by value.
-
operator that subtracts the right-hand-side
Duration
from the left-hand-side duration
and return a Duration
object by value. The result must
be 0 minutes and 0 seconds if the subtraction would result
in a "negative duration".
>
operator that returns true
if the left-hand-side Duration
is greater than the
right-hand-side Duration
, and false
otherwise.
=
operator that assigns the attributes of
the right-hand-side duration to the attributes of the
left-hand-side duration. (Note: It is very important to understand
this operator and how it works because several methods in other
classes will return a Duration
object that will be
assigned to another Duration
object.)
DurationHistory
class that
encapsulates a history of event durations (e.g. a sequence of
telephone calls). This class must use a doubly-linked linear
data structure that is allocated dynamically. (You must write a
Node
class to support this data structure.)
This class must keep track of the first and last Duration
entered in the history. It must also keep track of the
"current" Duration
(e.g., the most recently
requested Duration
).
At a minimum it must have the following methods:
void append(int minutes, int seconds)
method that
appends a new Duration
object to the end of the
history.
Duration getFirst()
method that returns
the first Duration
in the history and makes
it the "current" Duration
.
Duration getLast()
method that returns
the last Duration
in the history and makes
it the "current" Duration
.
Duration getNext()
method that returns the
Duration
in the history that is immediately after the
"current" Duration
. It must also make it the new
"current" Duration
.
Duration getPrevious()
method that returns
the Duration
in the history that is immediately
before the "current" Duration
. It must also make
it the new "current" Duration
.
bool hasNext()
method that returns true
if there is a Duration
in the history that is immediately
after the "current" Duration
and false
otherwise.
bool hasPrevious()
method that returns true
if there is a Duration
in the history that is immediately
before the "current" Duration
and false
otherwise.
Note the the various "get" methods will fail if they are called at inappropriate times. It is up to the caller to ensure that this does not happen.
Minder
that provides the
main functionality of the Madison Minute Minder.
At a minimum, it must have a Duration
attribute
that stores the user's monthly allotment of minutes and
a DurationHistory
that keeps track of the
user's telephone calls.
At a minimum it must have the following methods:
int
value that contains the user's monthly allotment of minutes.
void addCall(int minutes, int seconds)
method
that adds a telephone call (with the given duration) to the
history.
Duration getTimeLeft()
method that returns the
amount of time still available to be used for telephone calls.
(This method must return a duration of 0 minutes and 0 seconds if
the entire allotment has been used.)
Duration getTimeUsed()
method that returns the
amount of time used thus far (i.e., the total duration of all calls
in the history).
void reset(bool rollover)
method that "clears" the
history and gets the Minder
ready for a new month.
If the argument rollover
is true
the
unused portion of the allotment should be "rolled over" into the
new month. Otherwise, the new month should have the "normal"
allotment.
They are not useful for testing purposes but they can give you and idea of kind of drivers that will be used on "submission day".
I strongly suggest that you design, implement and test one class at a time. For the larger classes, I suggest that you design, implement and test one or two methods at a time.
I strongly suggest you use the make
utility.
Copyright 2010