Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language: C++ (Please follow the instructions given and if possible please add comments, thank you) Create a class called Time that has separate int member

Language: C++ (Please follow the instructions given and if possible please add comments, thank you)

Create a class called Time that has separate int member variables for hours, minutes, and seconds. Provide the following member functions for this class:

a. A no-argument constructor to initialize hour, minutes, and seconds to 0. b. 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. c. 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. d. 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. e. 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. f. 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

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions