Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 , and it takes a single integer argument that represents the number of seconds to sleep.)

Sample run:

image text in transcribed

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:27

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

Step: 3

blur-text-image

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

Explain the multicultural organization development (MCOD) process.

Answered: 1 week ago

Question

1. Who should participate and how will participants be recruited?

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago