0% found this document useful (0 votes)
24 views2 pages

Graded Lab Time Class

The document describes a graded lab assignment to create a Time class with functions like default constructor, constructor with parameters, copy constructor, setTime(), showTime(), tick(), addMinute(), addHour(), and AddTime() that adds two Time objects. It provides details on what each function should do and includes example code to test the Time class.

Uploaded by

Awam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Graded Lab Time Class

The document describes a graded lab assignment to create a Time class with functions like default constructor, constructor with parameters, copy constructor, setTime(), showTime(), tick(), addMinute(), addHour(), and AddTime() that adds two Time objects. It provides details on what each function should do and includes example code to test the Time class.

Uploaded by

Awam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Graded Lab (Time Class)

Lab Task

Create Time class making use of Copy constructor and functions:

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.

Your Time class should have the following member functions:

default constructor

This function initializes the Time object to contain 12 midnight (hour zero,
minute zero, seconds zero).

constructor with three parameters

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()

increment the minute with 1.

addHour()

Increment the hour with 1.

AddTime()

This function has one parameter which is Time object and returns a Time object which contains
the calculated time sum.

Time AddTime( Time);

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.

You might also like