Question: Write a program that prompts the user for a start time, a stop time, and a distance travelled (in miles) and computes the speed in
Write a program that prompts the user for a start time, a stop time, and a distance travelled (in miles) and computes the speed in miles per hour. Output the result rounded to the nearest tenth of a mile.
To keep track of the time, define a Time class. The Time class has a single integer data member minutes. Its interface consists of a default constructor, methods readTime and subtractTimes, as shown.
class Time {
public:
Time();
void readTime(bool & errFlag);
int subtractTimes(Time t);
private:
int minutes;
};
A Time consists of some number of hours and minutes, and is either before noon (AM) or after noon (PM).
Twelve noon is 12:00 pm and Twelve midnight is 12:00 AM.
All times are assumed to fall on the same day.
The readTime() method attempts to read, from cin, a time in the format
The subtractTime() method returns the difference, in minutes, between this Time and Time t. If this Time occurs prior to Time t, the returned difference is negative.
The main() function reads the distance travelled and the start time and stop time by calling the readTime() method. It computes the speed in miles per hour.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
