Add the following member function to the ADT class DigitalTime
defined in Displays 12.1 and 12.2:
This function computes the time interval between two values of type
DigitalTime. One of the values of type DigitalTime is the object that
calls the member function interval_since, and the other value of type
void DigitalTime::interval_since(const DigitalTime& a_previous_time,
int& hours_in_interval, int& minutes_in_interval) const
DigitalTime is given as the first argument. For example, consider the
following code:
DigitalTime current(5, 45), previous(2, 30);
int hours, minutes;
current.interval_since(previous, hours, minutes);
cout << "The time interval between " << previous
<< " and " << current << endl
<< "is " << hours << " hours and "
<< minutes << " minutes.\n";
In a program that uses your revised version of the DigitalTime ADT, this
code should produce the following output:
The time interval between 2:30 and 5:45
is 3 hours and 15 minutes.
Allow the time given by the first argument to be later in the day than the
time of the calling object. In this case, the time given as the first argument
is assumed to be on the previous day. You should also write a program to
test this revised ADT class.
Sorry the answer is not available at the moment…
If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.
Spread the 'tradition of sharing'.