Suppose you have a 12-hour clock (noon is 12 PM and midnight is 12 AM). Write a
ID: 3668075 • Letter: S
Question
Suppose you have a 12-hour clock (noon is 12 PM and midnight is 12 AM). Write a C++ program that reads in a current time, along with a time adjustment, and displays the resulting time after the adjustment. First, your program should take an input of the current hour and 'A' or 'P' to indicate AM or PM. Next, your program should ask how many hours forward or backwards you want to set the clock.
Compute and display the resulting time. Do not assume that the number of hours adjusted will be fewer than 24 hours. The output should be correct for any positive number entered. For example, a valid input would be to move a 7 P.M. clock forward by 70 hours.
Your program’s input and output should follow the format shown in the examples below, including the exact input and output prompts (including numerical format) and use of whitespace.
Example 1 (user input is bold):
Enter current time (A for AM, P for PM): 7 P
How many hours forwards or backwards do you want to move the clock (F for forwards, B for backwards): F 7
The new time is: 2 AM
Explanation / Answer
#include #include #include using namespace std; int main() { time_t t = time(NULL); tm* timePtr = localtime(&t); coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.