Question
Write a C++ program in which you are to declare a structure called Time that contains members to store the hours, minutes and seconds. You'll
Write a C++ program in which you are to declare a structure called Time that contains members to store the hours, minutes and seconds. You'll prompt the user for the input time and then call the GetTime function, which is responsible for getting three integer values from stdin, each which represent the hours, minutes and seconds. The GetTime function should test to see if each value is successfully extracted and if it is, to store it in the corresponding member of the Time parameter. If either the extraction fails or a particular value is out of range, then an appropriate error message is written to stdout, and the function returns a value of false. Otherwise, if all went well, a value of true is returned to the caller. (Note: this program assumes a zero-based 24-hour time, so the range of valid values for the hours is from 0 to 23, and for minutes and seconds, is 0 to 59.) If GetTime returns a value of true to the main function, then main will proceed to display the entered time in HH:MM:SS format, by calling the DispTime function. After the time has been displayed, main will then ask the user how many times they would like to see the time incremented. The user will enter an integer value in response, and a loop is then entered where the AddOneSecond function is called to add a second to the time, then DispTime will be called to display the incremented time. This happens as many times as the user wants to increment the time. To add a bit of realism to the whole thing, on each loop iteration a call is made to the sleep function, which causes the loop to suspend program execution for one second before continuing with the next loop iteration. This way it'll look more like a clock is running! (In case you're curious, the sleep function is available if you #include unistd.h , and it takes a single integer argument that represents the number of seconds to sleep.).Only use iostream and iomanip, and unistd.h if needed. Make comments with every line.
Sample run:
Enter time in HH:MM: SS format: 11:21:22 11:21:22 How many times would you like to see the time increment (seconds):5 11:21:23 11:21:24 11:21:25 11:21:26 11:21:27Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started