C++ Coding extra credit activity copiable code: #include // OTHER INCLUDES??? using namespace std; // YOUR CODE HERE #include "testcode.h" // For automatic grading purposes DO NOT REMOVE (but you can comment out temporarily for testing) int main() {
C++ Coding extra credit activity
copiable code:
#include <iostream>
// OTHER INCLUDES???
using namespace std;
// YOUR CODE HERE
#include "testcode.h" // For automatic grading purposes DO NOT REMOVE (but you can comment out temporarily for testing)
int main() {
testTimerClass(); // Test code for automatic grading. DO NOT REMOVE (but you can temporarily comment out for your own testing). Remove any test code you may have added prior to final submission.
}
Additional Files: testcode.h and testTimerClass
These files will automatically be compiled with your code. You cannot modify them.
testcode.h
using namespace std;
void testGetTime(){
Timer timer(true);
system("sleep 2");
cout << timer.getTime() << std::endl;
}
void testStartAndStop(){
Timer timer(true);
system("sleep 1");
timer.printTime();
timer.stop();
system("sleep 1");
timer.printTime();
timer.start();
system("sleep 1");
timer.printTime();
timer.stop();
system("sleep 1");
timer.printTime();
}
void testAddTimeToClock(){
Timer timer;
timer.addTimeToClock(60);
cout << timer.getTime() << std::endl;
}
void testReset(){
Timer timer;
timer.addTimeToClock(60);
timer.printTime();
timer.reset();
timer.printTime();
}
void testHoursMinutes(){
Timer timer;
timer.addTimeToClock(90);
timer.printTime();
timer.addTimeToClock(3600 * 2);
timer.printTime();
}
void testTimerClass(){
int testNumber;
cin >> testNumber;
switch (testNumber){
case 1: testStartAndStop(); break;
case 2: testAddTimeToClock(); break;
case 3: testReset(); break;
case 4: testHoursMinutes(); break;
}
}
![Timer Class
Concepts tested: Classes
1) Write a class called Timer that models a stopwatch with start, stop, and reset buttons. It has the following members:
a) -int startTime; // variable tracking when the timer was started (unused when timer is not running). In number of seconds since 1970
b) -int timeOnClock; // variable tracking the time on the clock since last reset in seconds
c) -bool isRunning; //variable tracking wether the clock is running or stopped
d) +Timer(); //constructor, initializes all to zero/false
e) +Timer(bool startNow); // constructur that starts clock automatically if startNow is true
f) +int getTime(); // returns time on clock in seconds. If clock is running, this must also include the time since it was last started
g) +void addTimeToClock(int seconds); // allows manually adding time to the clock
h) +void reset(); // resets time on clock to zero
i) +void start(); // starts clock
j) +void stop0; /I/ stops clock
k) +void printTime(); // prints the time (via cout) EXACTLY in the format Oh:0m:0s<newline>
2) Although you would normally create separate cpp and header files for your code, you must define and fully implement the class in the main file due to the constraints of
the lab environment
3) Class name and class member names MUST BE EXACTLY THE SAME as above
Example:
--If the timer is started and stopped after 2 seconds, a call getTime should return int integer 2. A call to printTime should print "Oh:0m:2s".
--If the same timer is then started and stopped after an hour, getTime() should return 3602 and printTime() should print "1h:0m:2s";
--If addTimeToClock(120) is then run, printTime() should print "1h:2m:2s";
--If timer
sreset, getTime() should return 0, and printTime() should print "Oh:0m:0s".](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2821f563-dabe-464d-a438-fd016e90b9a4%2F876d2474-936a-4b22-9469-419029524ceb%2Fdo5wuy_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)