Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Advanced Problem: Stopwatch Object:- Overview: In this assignment, the student will write a C++ program implements a Stopwatch object that utilizes the fast clock.

C++ Advanced Problem:

Stopwatch Object:-

Overview:

In this assignment, the student will write a C++ program implements a Stopwatch object that utilizes the fast clock.

When completing this assignment, the student should demonstrate mastery of the following concepts:

* Object-oriented Paradigm

* Fast Clock Timers

* Function kbhit()

* Function putch()

* Timing Stalls

* Object Modeling

Assignment Instructions:

Write a stopwatch class that uses timers to allow a user to make a call to start, stop, and display the current time on the stopwatch. Your stopwatch class should minimally implement methods that behave in the following way:-

StopWatch::StopWatch() - A default constructor method that initializes all internal state variables for the stopwatch. The stopwatch should begin with 0 seconds recorded on it.

bool StopWatch::Start() - A method that makes the stopwatch start to count time. Make sure this method only operates if the stopwatch is currently in the stopped state. The method will return true if the stopwatch was formerly stopped, but is now ticking as a result of this call.

bool StopWatch::Stop() - A method that makes the stopwatch stop counting time. When this method is call, the number of seconds and milliseconds that have elapsed between the call to Start and Stop should be recorded internally within the class. Nothing is displayed when the Stop() method is called. Stop() should only operate if the stopwatch is currently in the ticking state. The method will return true if the stopwatch was formerly ticking, but is now stopped as a result of this call.

bool StopWatch::IsTicking() A method that returns a boolean value indicating whether or not the stopwatch is currently ticking and accumulating time.

void StopWatch:DisplayTimerInfo() - This method should display the number of seconds and milliseconds that are currently stored in the stopwatch. The result should be displayed in decimal format with 4 points of precision.

Important Rules while programming your code:

Use the following Driver code to run your program. The code provides a model for displaying a simple progress bar so it is clear to the user when the stopwatch is ticking. You SHOULD NOT modify the Driver code in any way when completing this assignment. The Driver code makes use of two helper functions in the standard library, kbhit() and putch(). kbhit() is a function that queries the keyboard buffer and returns true if there are keys in the buffer that have not been processed. kbhit() will return false if the keyboard buffer is empty. Unlike other input functions you have used up to this point, kbhit() does not consume the key from the keyboard buffer when it is called. Instead, it simply inspects the buffer and returns an appropriate value. putch() is a function that places an ASCII symbol on the display. In the provided driver code, putch() is being used to display the carriage return symbol, which causes the cursor to move to the beginning of the output line, but not drop down. It IS NOT required that you completely understand the way the progress bar is being displayed (its rather cool though, so you should definitely check it out). Your job is to write the stopwatch class so it properly interfaces with the provided driver.

Driver [Starter code]:

// INCLUDES & NAMESPACES

#include

#include

#include

#include "stopWatch.h"

using namespace std;

// PROTOTYPES

void sleep(clock_t delayInMS);

// MAIN

int main() {

int progressCounter = 0;

int progressStriker = 0;

// make the timer

StopWatch myTimer;

// start the timer

cout << "Press any key to start the stopwatch..." << endl;

getch();

myTimer.Start();

// display progress bar flicker

cout << "The stopwatch has been started, press any key to stop it..." << endl;

progressCounter = 1;

progressStriker = 0;

while( !kbhit() ) {

// display the appropriate timing symbol

if(progressStriker % 2 == 0)

cout << ".";

else

cout << " ";

// if the progress bar reaches the end of the line

// goto a new line and change the timing symbol

progressCounter++;

if(progressCounter == 80) {

progressCounter = 1;

progressStriker++;

putch(13); // carriage return

}

// wait 10ms between each timing symbol

sleep(10);

}

cout << endl;

// stop the timer

myTimer.Stop();

// display the timer contents

myTimer.DisplayTimerInfo();

// pause the screen and end the program

getch();

return 0;

}

void sleep(clock_t delayInMS) {

clock_t targetTime = clock() + delayInMS;

while(clock() < targetTime);

}

You might strictly need to follow the directions as listed above the Driver code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago