CS12 Lab 3
Week of October 15—19
This lab deals with adding methods to a user defined
class.
To Do
-
Use the time class in your book. Copy
the files time3.h
and time3.cpp
on pp 423-424 in the book (or just download them by clicking on the links).
-
Open a new project and include both files in it.
- Add a new member function o the Time class, called tick()
, that increments the time stored in a time object by one second. Be sure
to check that the values of the data members second,
minute, and hour contain legal values after this
operation.
- Write a short main program (in a separate file), that
tests the new method. The program should
declare Time objects with the following values: 2:35:17,
15:21:59, 8:59:59, and 23:59:59. Your program should apply the tick()
method to each of these objects, and print the new value of the object.
- Compile and run the project and verify correct output (the new time
values should be 2:35:18, 15:22:00, 9:00:00, and 0:0:0).
Extra Credit
- Add another method, tick(int add), that
increments the time value by add seconds (rather than one
second).