Question: Create a class called time that has three separate private int member data for hours, minutes, and seconds. One default constructor should initialize the int

Create a class called time that has three separate private int member data for hours, minutes, and seconds. One default constructor should initialize the int data to 1 for hours, and 0 for minutes and seconds; another parameterized constructor should initialize it to fixed values of 10, 10, and 10 for hours, minutes, and seconds (arguments 10,10,10 provided in hard-coded fashion during object declaration in main()) respectively. A public member function should receive the time data from the user in 24 hours format; whereas a public member function should display the time in 24 hours (11:59:59) format. A private member function check_time(), should validate that if the user provides the value of the time (hr:min:sec) using the mutator (setter) function of the class for an object, then the values are greater than 0 and less than or equal to 24 for hours; greater than or equal to 0 and less than or equal to 60 for minutes and seconds. If an incorrect value is entered as input by the user, they should be prompted about the error and asked to re-enter the values.

A non-member function addTime() should add multiple objects of type time passed as arguments to this non-member function. Consider declaring addTime() as a friend of the class time. In order to perform the addition of the time objects inside of the body of addTime(), overload the binary addition operator +, by declaring and defining it as a public member function of class time.

The main() program should create an initialized time object which will invoke the parameterized constructor (hard code the values 10,10,10 during this object declaration) and a second object which will be invoking the default constructor. A third object should be created whose values will be initialized by the user by invoking the mutator (setter) function in the class time. Thereafter, the initial times of the all the three objects should be displayed back to the user by using the accessor (getter) function of the class. Finally, addTime() should be invoked and the values of all the three objects should be added together storing the result in a fourth time object. Thereafter the result stored in the fourth object should be displayed to the user by again using the accessor (getter) function. Additionally, your program must have a custom header file to declare the class, functions, and other primitive header files that you might need for your program.

Sample Output: (These values should not be used in final submission; please use values from Section Input Cases)

Enter Time in 24 hours format (Hours: Minutes: Seconds)

-2

15

45

You have entered an invalid time value, hours should between 1 and 24; minutes and seconds should be between 0 and 60. Please try Again:

Enter Time in 24 hours format (Hours: Minutes: Seconds) 4 11 15 Thank you!

Your first time value is: 10:10:10

Your second time value is: 1:0:0

Your third time value is: 4:11:15

Total time that has passed is: 15:21:25 End of Program!

Do you want to try again?

Press Y for yes or N for no

END SAMPLE

[NOTE: it is okay if time values over-shoot their upper bounds (24 and 60) for the final object since it is the total time passed. So, do not call check_time() with respect to total time computations]

Input Cases:

Case1 : User input: -7:27:78

Case2: User input: 15:26:45

Case3: User input: 05:54:59

Case4: User input: 21:06:33

Note: Each input case is independent of each other. DO NOT add the time of consecutive input cases.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!