Question: // timer.h for CMPSC122 lab // Measure time in Window // Define a Timer object t, use t.start() for beginning of the algorithm, t.stop() for

// timer.h for CMPSC122 lab
// Measure time in Window
// Define a Timer object t, use t.start() for beginning of the algorithm, t.stop() for the ending, and t.show() for printing.
#ifndef TIMER_H
#define TIMER_H
#include
#include
#include
using namespace std;
class Timer
{
public:
Timer();
Timer(const std::string &label);
~Timer();
void start(void);
void stop(void);
void show(void);
private:
void reset(void);
string label;
long tps;
clock_t
start_time,
end_time;
double
usertime,
systemtime,
elapsedtime,
waittime;
};
#endif
// eof timer.h
// timer.cpp
Timer::Timer()
{
label = "Process Timer";
reset();
}
Timer::Timer(const std::string &label)
{
Timer::label = label;
reset();
}
Timer::~Timer()
{
}
void
Timer::reset(void)
{
tps = CLOCKS_PER_SEC;
end_time = 0;
usertime = 0;
systemtime = 0;
elapsedtime = 0;
waittime = 0;
}
void
Timer::start(void)
{
start_time = clock();
}
void
Timer::show(void)
{
cout
}
void
Timer::stop(void)
{
end_time = clock();
elapsedtime = ((double)(end_time -
start_time) / (double)tps);
if (elapsedtime
{
elapsedtime = 0.001;
}
if (waittime
{
waittime = 0.00;
}
}
// eof timer.cpp
note: The computing times of this algorithm is very high, and the number of paths may be overflow, don't try input numbers even over 16.
Sample Run
How many points north of A is B? 2
How many points east of A is B? 3
There are 10 northeast paths between A and B.
Process Timer
-------------------------------
Elapsed Time : 0.01s
Enter y or Y to continue next example or any other letter to exit: y
How many points north of A is B? 12
How many points east of A is B? 14
There are 9657700 northeast paths between A and B.
Process Timer
-------------------------------
Elapsed Time : 1.081s
Enter y or Y to continue next example or any other letter to exit: y
How many points north of A is B? 16
How many points east of A is B? 16
There are 601080390 northeast paths between A and B.
Process Timer
-------------------------------
Elapsed Time : 62.79s
Enter y or Y to continue next example or any other letter to exit:
Consider a network of streets laid out in a rectangular grid, for example In a northeast path from one point in the grid to another, one may walk only to the north (up) and to the east (right). For example, there are four northeast paths from A to B in the preceding grid: Write a program that must use a recursive function to count the number of northeast paths from one point to another in a rectangular grid. Your program should prompt user to input the numbers of points to north and to east respectively, and then output the total number of paths
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
