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 : , where is an integer between 1 and 12, is an integer between 0 and 59, and is either AM or PM. If a properly formatted time is read, the readTime() method sets errFlag to false and the value of Time variable, minutes, is set to the time read in minutes; otherwise errFlag is set to True. This error is checked in the main() function and an appropriate message is displayed prompting the user to either exit or type in a valid time and continue.

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!