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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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".
Transcribed Image Text: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".
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education