https://aaronbloomfield.github.io/pdr/labs/lab06/index.htmlI need this lab but only the first two parts are due tonight the last is due tomorrow

1 answer below »

https://aaronbloomfield.github.io/pdr/labs/lab06/index.htmlI need this lab but only the first two parts are due tonight the last is due tomorrow
Answered 2 days AfterMar 31, 2021

Answer To: https://aaronbloomfield.github.io/pdr/labs/lab06/index.htmlI need this lab but only the first two...

Kamal answered on Apr 02 2021
156 Votes
timer.cpp
#include "timer.h"
timer::timer() {
running = false;
}
timer::timer(timer& t) {
running = t.running;
start_time
= t.start_time;
stop_time = t.stop_time;
}
void timer::start() {
if (!running) {
running = true;
start_time = steady_clock::now();
}
}
void timer::stop() {
if (running) {
running = false;
stop_time = steady_clock::now();
}
}
// Returns the time elapsed, in seconds
double timer::getTime() {
// Cast the intrinsic duration to seconds, but use a double so that we can
// have fractional seconds to represent anything more precise (i.e. microseconds)
return duration_cast>(stop_time - start_time).count();
}
ostream& operator<<(ostream& out, timer& t) {
return out << to_string(t.getTime());
}
timer.h
// This timer typically has 1/1000000 second (1 micro-second) accuracy
// under most Linux distributions
#ifndef TIMER_H
#define TIMER_H
#include
#include
#include
using namespace std;
using namespace std::chrono;
class timer {
public:
timer();
timer(timer& myTimer);
void start();
void stop();
// Returns the time elapsed, in seconds
double getTime();
private:
steady_clock::time_point start_time, stop_time;
bool running;
};
ostream& operator<<(ostream& theStream, timer&...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here