rom time to time in programming it comes in handy to be able

rom time to time in programming, it comes in handy to be able to determine how long it takes/took to perform a certain action(s). (See, for instance, the sort timing lab.)

You are to write a class which will allow an easy interface to the computer\'s timing facilities. When you first create a Timerobject, it should be set to a \'stop\' state. When the programmer wants to use it to time something, they can call the start() method before the \'something\' executes and then call the stop() method afterward the \'something\' finishes. To determine how long the \'something\' took, they\'ll call the elapsed() method. This elapsed time will be reported in (whole) seconds.

Unfortunately, this describes extremely simple operation and may not suit all programmers\' needs. To allow more general usage of the class, we\'ll also allow the programmer to start the timer at the object\'s declaration. We\'ll also allow the programmer to get the elapsed time whether the timer is still running or not. Finally, we\'ll provide an output() method so the programmer can directly print the currently elapsed time without having to retrieve it separately.

In addition, allow the programmer to subtract() and add() two Timerobjects to receive a Timerobject that is the difference/total of the original two Timers\' currently elapsed times. (The resulting object should not be running.)

Then we have to boobie-proof the class. Make sure that things work correctly if the programmer tries to get/print the elapsed time of a Timerobject which has never been started. Make sure nothing goes wrong if the programmer tries to stop a Timerobject that isn\'t currently running.

We won\'t need a reset() method since the programmer can simply call start() again to start over...

Solution

Consider a class Loop time

Class LoopTime

{

void Loopime(Int nMax = 1000000) {

TStopwatch timer;

timer.Start();
for(Int_t i=0; i<nMax; i++);
timer.Stop();

cout << \" Cpu time for \"<< nMax << \" iterations \" << timer.CpuTime() << endl;
}

}

void main()

{

LoopTime= new LoopTime();

}

rom time to time in programming, it comes in handy to be able to determine how long it takes/took to perform a certain action(s). (See, for instance, the sort t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site