/* Timer class code plus a little demo program */ #include #include #include "timer.h" using namespace std; /* Time class code */ // constructor cTimer::cTimer(void) { setTime = clock(); } // start the timer void cTimer::startTimer() { setTime = clock(); } // wait numSeconds after timer set void cTimer::endTimer(float numSeconds) { clock_t nowTime; nowTime=clock(); while (numSeconds > (float) (nowTime-setTime)/ (float) CLK_TCK) { nowTime=clock(); } return; } /* This little program demonstrates a simple timer. Run the program, enter some number of seconds, the program will delay that long before continuing. */ main() { cTimer theTimer; float numSeconds=0.1; while (numSeconds > 0) { cout << "Enter number of seconds to wait." << endl; cin >> numSeconds; theTimer.startTimer(); theTimer.endTimer(numSeconds); } }