Question
Language: C++ (Please follow the instructions given and if possible please add comments, thank you) (It should ask for the input for time) Create a
Language: C++
(Please follow the instructions given and if possible please add comments, thank you)
(It should ask for the input for time)
Create a class called Time that has separate int member variables for hours, minutes, and seconds. Provide the following member functions for this class: 1. A no-argument constructor to initialize hour, minutes, and seconds to 0.
2. A 3-argument constructor to initialize the members to values sent from the calling function at the time of creation of an object. Make sure that valid values are provided for all the data members. In case of an invalid value, set the variable to 0.
3. A member function show() to display time in 11:59:59 format. You can also overload the << operator so that you can display the object directly. This will allow you to properly test your pre- and -post increment/decrement operators.
4. An overloaded operator+ for addition of two Time objects. Each time unit of one object must add into the corresponding time unit of the other object. Keep in view the fact that minutes and seconds of resultant should not exceed the maximum limit (60). If any of them do exceed, subtract 60 from the corresponding unit and add a 1 to the next higher unit.
5. Overloaded operators for pre- and post-increment. These increment operators should add a 1 to the seconds unit of time. Keep track that seconds should not exceed 60.
6. Overloaded operators for pre- and post-decrement. These decrement operators should subtract a 1 from seconds unit of time. If number of seconds goes below 0, take appropriate actions to make this value valid.
A main() program should create two initialized Time objects and one that isnt initialized. Then it should add the two initialized values together, leaving the result in the third Time variable. Finally it should display the value of this third variable. Check the functionalities of ++ and -- operators of this program for both pre- and post-incrementation.
Step 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