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 conversions will have a call-by-reference formal parameter of type char to record whether it is AM or PM. (The function will have other parameters as well.) Include a loop that lets the user repeat this computation for new input values again and again until the user says he or she wants to end the program.
Each iteration of the loop will process 3 inputs:
You mustimplement 4 functions. You are notpermitted to change the name or signature of these functions; the testing framework is going to directly call the functions. The three functions and their signatures are (use the signatures as a hint for how to implement this!):
Sample execution:
Enter the hour in 24-hour format: 9 Enter the minute in 24-hour format: 13 The time in 24-hour format is 09:13 The time in 12-hour format is 09:13AM Continue? (y/n): y Enter the hour in 24-hour format: 12 Enter the minute in 24-hour format: 55 The time in 24-hour format is 12:55 The time in 12-hour format is 12:55PM Continue? (y/n): y Enter the hour in 24-hour format: 14 Enter the minute in 24-hour format: 05 The time in 24-hour format is 14:05 The time in 12-hour format is 02:05PM Continue? (y/n): n
/****************************time.cpp**************************************/
#include <iostream>
using namespace std;
void get_input(int &hour, int &minute);
void convert_to_12_hour(int &hour, char &am_pm);
void print_24_hour_time(int hour, int minute);
void print_12_hour_time(int hour, int minute, char am_pm);
int main()
{
//variable declaration
int hour, minute;//stroe hours and minutes
char am_pm; //store am or pm
char op; //store option that user want to continue or not
do
{
//calling functions
get_input(hour, minute);
print_24_hour_time(hour, minute);
convert_to_12_hour(hour, am_pm);
print_12_hour_time(hour, minute, am_pm);
cout << endl << "Continue? (y/n): ";
cin >> op;
}
while(op == 'y' || op == 'Y');
return 0;
}
void get_input(int& hours, int& minutes)
{
do
{
cout << "Enter the hour in 24-hour format: ";
cin >> hours;
if(hours > 23) cout << "Please enter a value between 0 and
23" << endl;
}
while(hours > 23);
do
{
cout << "Enter the minute in 24-hour format: ";
cin >> minutes;
if(minutes > 59) cout << "Please enter a value between 0
and 59" << endl;
}
while(minutes > 59);
}
void convert_to_12_hour(int& hours, char& am_pm)
{
if(hours > 12)
{
hours = hours - 12;
am_pm = 'P';
}
else if(hours == 12){
am_pm = 'P';
}
else
am_pm = 'A';
}
void print_24_hour_time(int hours, int minutes){
//add 0 before 0-9
if(hours<10&&minutes < 10)
cout <<"The time in 24-hour format is 0"<< hours
<< ":0" << minutes;
else if(hours<10)
cout <<"The time in 24-hour format is 0"<< hours
<< ":" << minutes;
else if(minutes<10)
cout <<"The time in 24-hour format is "<< hours
<< ":0" << minutes;
else
cout <<"The time in 24-hour format is "<< hours
<< ":" << minutes;
}
void print_12_hour_time(int hour, int minute, char am_pm)
{
cout<<endl;
if(am_pm == 'P')
{
//add 0 before 0-9
if(hour<10&&minute < 10)
cout <<"The time in 12-hour format is 0"<< hour
<< ":0" << minute << " PM";
else if(hour<10)
cout <<"The time in 12-hour format is 0"<< hour
<< ":" << minute << " PM";
else if(minute<10)
cout <<"The time in 12-hour format is "<< hour <<
":0" << minute << " PM";
else
cout <<"The time in 12-hour format is "<< hour <<
":" << minute << " PM";
}
else
{
if(hour<10&&minute < 10)
cout <<"The time in 12-hour format is 0"<< hour
<< ":0" << minute << " AM";
else if(hour<10)
cout <<"The time in 12-hour format is 0"<< hour
<< ":" << minute << " AM";
else if(minute<10)
cout <<"The time in 12-hour format is "<< hour <<
":0" << minute << " AM";
else
cout <<"The time in 12-hour format is "<< hour <<
":" << minute << " AM";
}
}
/********************************************output**************************************/
Enter the hour in 24-hour format: 14
Enter the minute in 24-hour format: 05
The time in 24-hour format is 14:05
The time in 12-hour format is 02:05 PM
Continue? (y/n): y
Enter the hour in 24-hour format: 11
Enter the minute in 24-hour format: 5
The time in 24-hour format is 11:05
The time in 12-hour format is 11:05 AM
Continue? (y/n): n

Thanks a lot, Please let me know if you have any problem......................
C++ PROGRAM Write a program that converts from 24-hour notation to 12-hour notation. For example, it...
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...
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...
Need some assistance of
reorganizing this whole program. I have the right code for
everything I just need help on putting all the codes in the right
spot so it can come out to the correct output.
output is supposed to look like this:
1 \\ user inputs choice to convert 12 to 24
8 \\ user inputs 8 for hours
30 \\ user inputs 30 for minutes
20 \\ user inputs 20 for seconds
AM \\ user inputs AM...
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 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...
a C++ program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule: a. Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute. b. Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through Friday, is charged at a rate of $0.25 per minute. c. Any call started on a Saturday or Sunday is charged...
Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...
I need help with a Python program that has error checking loops. Hour must be a number from 1 to 12. Minute and second must be numbers from 0 to 59. Also check whether “AM” or “PM” is entered. Every time an invalid value is entered, display an error message and ask the user to re-enter a valid value immediately. Functions are not covered yet and are not necessary. Thanks. The following is an example: Enter hour: 0 Hour must...