Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP ME IMPROVE WTIH THIS CODE IN C + + PROGRAMMING C + + CODE: #include #include using namespace std; int computeDifference ( int

PLEASE HELP ME IMPROVE WTIH THIS CODE IN C++ PROGRAMMING
C++ CODE:
#include
#include
using namespace std;
int computeDifference(int startHour, int startMin, bool isStartAM, int futureHour, int futureMin, bool isFutureAM){
// Convert start and future times to 24-hour format
if (!isStartAM && startHour !=12){
startHour +=12;
}
if (!isFutureAM && futureHour !=12){
futureHour +=12;
}
if (isStartAM && startHour ==12){
startHour =0;
}
if (isFutureAM && futureHour ==12){
futureHour =0;
}
// Calculate time difference in minutes
int startTotalMin = startHour *60+ startMin;
int futureTotalMin = futureHour *60+ futureMin;
int difference = futureTotalMin - startTotalMin;
if (difference 0){
difference +=24*60;
}
return difference;
}
int main(){
// Get user input for start time
int startHour, startMin, futureHour, futureMin;
char startPeriod, futurePeriod;
cout "Enter start time (in format HH:MM AM/PM): ";
cin >> startHour;
cin.ignore(1,':'); // Ignore colon delimiter
cin >> startMin >> startPeriod;
bool isStartAM =(startPeriod =='A'|| startPeriod =='a');
// Get user input for future time
cout "Enter future time (in format HH:MM AM/PM): ";
cin >> futureHour;
cin.ignore(1,':'); // Ignore colon delimiter
cin >> futureMin >> futurePeriod;
bool isFutureAM =(futurePeriod =='A'|| futurePeriod =='a');
// Compute time difference and display result
int difference = computeDifference(startHour, startMin, isStartAM, futureHour, futureMin, isFutureAM);
cout "Time difference in minutes: " difference endl;
return 0;
}
Additional intructions:
Modify the time machine application to go back - and - forth Multiple times
by entering the time desired minutes. It could be that the user can move
forward further or go back
For example :
Present and Future time are fixed and minutes difference are to be computed
Initial time : 5:15 AM
Second time : 6:30PM
Third to succeeding iteration can be achieved by deducting or adding intervals
per minutes
Third time : 4:30 AM
Fourth time : 2:30 AM
Initial time :
Future time :
Minutes Difference:
Would you like to travel more ?
Yes...
Enter Minutes :
You are now in:
Would you like to travel more ?
Yes...
Enter Minutes :
You are now in:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions