Time Displacement (12-hour format)
Write a program that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24-hour notation for the input time and 12-hour notation for the output time. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants to end the program.
Each iteration of the loop will process 5 inputs:
Sample execution:
Enter current hour: 12 Enter current minute: 00 Enter waiting period hour: 4 Enter waiting period minute: 25 The time will be 04:25PM Continue? (y/n): y
Enter current hour: 0 Enter current minute: 15 Enter waiting period hour: 72 Enter waiting period minute: 00 The time will be 12:15AM Continue? (y/n): n
Code
===============================================================
#include <iostream>
#include <string>
using namespace std;
int main() {
//declare variables for storing the inputs
string choice;
int current_h;
int current_min;
int wait_h;
int wait_min;
//infinite while loop
while(true)
{
//input for current hour and min
cout<<"Enter current hour: ";
cin>>current_h;
cout<<"Enter current minutes:";
cin>>current_min;
//input for period hour and min
cout<<"Enter waiting period hour: ";
cin>>wait_h;
cout<<"Enter waiting period minute: ";
cin>>wait_min;
//add hours and mins
//remember that input is taken in 24 hour format
int hour = current_h+wait_h;
int mins = current_min+wait_min;
//if minutes are greater than 60 after adding than
//increase hour by 1 and decrease nins by 60
if(mins>60)
{
mins-= 60;
hour+= 1;
}
//now if houra are greater than taking modulo with 24 will
//give the exact hours
hour=hour%24;
//we can also get hours as 0 but final output should be in
//12 hour format so change it to 12
if(hour==0){hour=12;}
unsigned int number_of_digits = 0;
int n = hour;
do {
++number_of_digits;
n /= 10;
} while (n);
//if hour is smaller than 12 then its AM
if(hour<=12)
{
if(number_of_digits==1){
cout<<"The time will be
"<<0<<hour<<":"<<mins<<"AM"<<endl;
}
else{
cout<<"The time will be
"<<hour<<":"<<mins<<"AM"<<endl;
}
}
//otherwise its PM
else
{
hour-=12;
n = hour;
do {
++number_of_digits;
n /= 10;
} while (n);
if(number_of_digits==1){
cout<<"The time will be
"<<0<<hour<<":"<<mins<<"PM"<<endl;
}
else{
cout<<"The time will be
"<<hour<<":"<<mins<<"PM"<<endl;
}
}
//ask the user to continue the loop or not
cout<<"Continue?(y/n):";
cin>>choice;
cout<<"\n"<<endl;
if(choice=="n"){
break;
}
}
}
===================================================================
OUTPUT

Time Displacement (12-hour format) Write a program that requests the current time and a waiting time...
Write a program (C++) that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24-hour notation for the times. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants to end the program.You can assume the wait time will always...
C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it should convert 14:25 to 2:25 PM. The input is given as two integers. There should be at least three functions, one for input, one to do the conversion, and two for output (one for 12-hour time and another for 24-hour time). Record the AM/PM information as a value of type char, ‘A’ for AM and ‘P’ for PM. Thus, the function for doing the...
in C++ Write a program that converts a time in 12-hour format to 24-hour format. The program will prompt the user to enter a time in HH:MM:SS AM/PM form. (The time must be entered exactly in this format all on one line.) It will then convert the time to 24 hour form. You may use a string type to read in the entire time at once including the space or you may choose to use separate variables for the hours,...
1
Write a program to convert the time from 24-hour notation to
12-hour notation and vice versa. Your program must be menu driven,
giving the user the choice of converting the time between the two
notations. Furthermore, your program must contain at least the
following functions:
a function to convert the time from 24-hour notation
to 12-hour notation,
a function to convert the time from 12-hour notation
to 24-hour notation,
a function to display the choices, function(s) to get
the...
Create the Code using C Program: 2. Write a program to convert the time from 24-hour notation to 12-hour notation and vice-versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the...
In python 3, 1. Write a program that takes a number of credit hours and returns a classification as follows: 29 credits or less: freshman; 30-59 credits: sophomore; 60-89 credits: junior; 90+ credits: senior. 2. Use a loop to valid input such that users can only enter positive numbers. 3. Use a loop to allow the user to keep entering credit hours and receiving classifications until they quit. All code must be in a function. I suggest the following structure:...
IN C++ pls. Modify the Time class of Figs. 9.8–9.9 of your book to include a tick member function that increments the time stored in a Time object by one second. Write a program that tests the tick member function in a loop that prints the time in standard format during each iteration of the loop to illustrate that the tick member function works correctly. Be sure to test the following cases: a) Incrementing into the next minute. b) Incrementing...
PLEASE I NEED C# Objectives Learn the basics of exception handling. Background Exceptions are essentially unexpected situations. It is difficult to write a program that can handle all possible situations, as we have found out through the many programs we have written. For example, should your program accept accidental input? Does it use the metric system or the empirical system? Do users of your program know which system it uses? In order to deal with all these possibilities, exceptions were...
Write a code for a ride tracking app for Large Resort parks. In your app users are going to be able to track wait times for up to five attractions, find the shortest wait time, and find the average wait time. //-----------------------------Sample Program Behavior with five attractions entered--------------------- Welcome to Large Resort Parks! Please enter the attractions you plan to visit and their wait times Ride 1 info: Attraction Name: 80 ft drop Wait time (in minutes): 40 Enter another...
In C++, Write a program that reads in a length in meters and will output the equivalent length in feet and inches. Express feet as an integer and inches to the nearest 1/100 of an inch. You must write and use a function that uses the following function prototype to perform the calculation: void MtoFtIn(double meters, int& feet, double& inches); The function should not input any data or print any results, it only does the calculation. Include a loop that...