// // Programmer: Craig Stuart Sapp // Creation Date: Sat Sep 19 14:00:20 PDT 1998 // Last Modified: Sat Sep 19 14:00:27 PDT 1998 // Filename: .../sig/doc/classes/Timer/examples/ex-3-Timer.cc // Syntax: C++ // $Smake: g++ -O -o %b -lsig %f && strip %b // // Description: This program will count to 10, with one number // displayed per second. The timer is counting // in arbitrary units of time, but we are still able // to count time in seconds. The flush command // in the print statement prevents buffering of the counted // number by forcing it to print immediately. #include "Timer.h" #include #include int main(void) { Timer stopwatch; int counter = 0; stopwatch.reset(); // set tick rate between 100 and 999 ticks per second: stopwatch.setTicksPerSecond(rand() % 900 + 100); while (counter <= 10) { if (stopwatch.getTime() > counter * stopwatch.getTicksPerSecond()) { cout << counter << " " << flush; counter++; } } cout << endl; return 0; }