Graded Lab Time Class
Graded Lab Time Class
Lab Task
In this lab you will write a class called Time. The Time class will have three data members:
hours, minutes, and seconds (all int). Times will be stored using a 24-hour clock, so 10 AM
is stored as 10 and 10 PM is stored as 22.
default constructor
This function initializes the Time object to contain 12 midnight (hour zero,
minute zero, seconds zero).
This function has parameters for the hour, minutes, and seconds. It initializes the Time object
to the values given by the parameters.
copy constructor
This function initializes the Time object to contain the same values as the parameters.
setTime()
This function has parameters for the hour, minute, and second, and returns void. setTime sets
the time to the values given by the parameters.
showTime()
This function has no parameters and returns void. It prints the time using the normal 12 hours
clock and AM/PM designation. For example, if hours is 21, minutes is 32 and seconds is 5, the
time should be displayed as 9:32:05 PM. If hours is 5, minutes is 12, and seconds is 45, the
time should be displayed as 5:12:45 AM. Don't forget to add a leading zero if the minutes
and/or the seconds contains a value less than 10!
tick()
This function has no parameters and returns void. It increments the time by one second,
adjusting the minutes and hours if necessary.
addMinute()
addHour()
AddTime()
This function has one parameter which is Time object and returns a Time object which contains
the calculated time sum.
Write client code to test your Time class. Your main function should:
• Create two Time objects and prompt the user to enter values for the Time objects.
• Print the Time objects.
• Tick the first Time object 100 times, then print the first Time object.
• Tick the Second Time object 30 times, then print the second Time object.
• Create a third Time object that is initialized by the default constructor.
• Create a fourth Time object that is initialized to 10:56:05.
• Create a fifth Time object that is initialized to be a copy of the fourth Time object.
• Print the third, fourth, and fifth Time objects.