This lab will help you practice with classes.
From time to time in programming, it comes in handy to be able to determine how long it takes/took to perform a certain action(s). (See, for instance, the sort timing lab.)
You are to write a class which will allow an easy interface to the computer's timing facilities. When you first create a Timer object, it should be set to a 'stop' state. When the programmer wants to use it to time something, they can call the start() method before the 'something' executes and then call the stop() method afterward the 'something' finishes. To determine how long the 'something' took, they'll call the elapsed() method. This elapsed time will be reported in (whole) seconds.
Unfortunately, this describes extremely simple operation and may not suit all programmers' needs. To allow more general usage of the class, we'll also allow the programmer to start the timer at the object's declaration. We'll also allow the programmer to get the elapsed time whether the timer is still running or not. Finally, we'll provide an output() method so the programmer can directly print the currently elapsed time without having to retrieve it separately.
In addition, allow the programmer to subtract() and add() two Timer objects to receive a Timer object that is the difference/total of the original two Timers' currently elapsed times. (The resulting object should not be running.)
Then we have to boobie-proof the class. Make sure that things work correctly if the programmer tries to get/print the elapsed time of a Timer object which has never been started. Make sure nothing goes wrong if the programmer tries to stop a Timer object that isn't currently running.
We won't need a reset() method since the programmer can simply call start() again to start over...
It makes no sense to me, but people keep wanting to call the functions localtime and asctime from the standard C library ctime here. Just don't! They do nothing useful here! (And asctime leaves a mess behind you would probably forget to clean up even if you knew how!)
Finally, place your Timer class in a library and write a test application that makes sure it is working properly. The easiest way would be to print the current system time, start the Timer, and ask the tester to wait for a while before hitting Enter. Then, when they do hit Enter, stop the Timer and print both the Timer's elapsed seconds and the system time. Then the tester can check the elapsed time for themselves. Place this interaction in a yes/no loop so the tester can repeat the testing easily by simply saying 'yes' or 'no' to your question of whether or not to continue. (Of course, IGWOS that your loop should allow the tester to enter either y/n or the full words yes/no. But don't worry about them typing 'yellow' or 'Naugahyde' or whatever.)
This assignment is (Level 3).
Add (Level 2) to properly apply inline'ing and const-ness to all of your class methods. (This includes proper use of initializer lists on constructors!)
Add (Level 2) to provide the tester with a menu of different testing methods (that is, means of testing -- not class methods that do testing). One should be the above 'hit Enter' method. Others should focus on printing the system time, performing some action multiple times, and printing the elapsed and system times for verification.
Note: this version will have a 'Quit' option in the menu instead of the yes/no loop.
Note 2: options are to be choose-able by number or significant letter(s) -- as all our menus have been.
Note 3: when the tester is choosing by significant letter, they might actually type the whole word that significant letter begins.
Note 4: you can use this opportunity to correct the testing omissions you found in the thought-provoking question above.
Note 5: you'll receive additional (Levels) for each good alternative testing method after the second. (So you need to provide at least 3 testing methods and after that you get more credit depending on how good the tests are.)
If you did all above options, this lab could be worth as much as (Level 7+).