Step 1
Following is the c++ program:
Variables used:
startHours, startMins are used to store the starting time of time machine.
futureHours, futureMins are used to store the future time of time machine.
xAM variable is used to store meridiem of start and future time.
isSAM is boolean variable that is true if starting time is AM.
isFAM is boolean variable that is true if future time is AM.
Functions:
main() is used to call computeDifference() function that will calculate the difference between the start and future time.
computeDifference() takes as input six variables from the user and then apply the following logic to compute the difference between the start and future time:
If Meridien of both start and future time are the same, then simply subtract the start time from the future time.
Difference = future minutes – start minutes
If Meridien of both start and future time are different, then apply the following formula to calculate difference:
Difference = (12 * 60 – start minutes) + future minutes
Step 2
Program :
#include <iostream> //header file for input and output
using namespace std;
//calculate the time difference(in minutes) between start time and future time.
int computeDifference(int startHours, int startMins, bool isSAM, int futureHours, int futureMins, bool isFAM) {
int difference = 0; //to store difference
startMins = startHours * 60 + startMins; //converting in minutes.
futureMins = futureHours * 60 + futureMins; //converting in minutes.
//applying formula for difference.
if (isSAM == isFAM) {
difference = futureMins - startMins;
} else if (isSAM == true && isFAM == false) {
difference = (12 * 60 - startMins) + futureMins;
}
}
int main() {
int startHours, startMins; //it will store start time
int futureHours, futureMins; //it will store future time.
string xAM; //it will store meridiem.
bool isSAM; //it will be true if start time is AM.
bool isFAM; //it will be true if future time is in AM.
int difference = 0; //it will store difference.
cout << "Enter start time of time machine as 'HH MM AM/PM': "; //take input from