1 /* 2 * Timer Class 3 * By Danny Battison 4 * gabehabe@hotmail.com 5 */ 6 7 #include8 9 class CTimer 10 { 11 public: // everything is public for ease of access 12 // begin/end variables 13 clock_t begin; 14 clock_t end; 15 16 // variable declarations used for time calculation 17 double elapTicks; 18 double elapMilli, elapSeconds, elapMinutes; 19 20 // constructor 21 CTimer () {} 22 //call myTimer.begin () to begin the timer 23 void start() 24 { 25 this->begin = clock () * CLK_TCK; 26 } 27 // call myTimer.stop () to stop the timer 28 void stop () 29 { 30 this->end = clock () * CLK_TCK; getTimes (); 31 } 32 33 // call getTimes 34 void getTimes () 35 { 36 // variable definitions on to calculate time taken 37 this->elapTicks = this->end - this->begin; // stop the timer, and calculete the time taken 38 this->elapMilli = this->elapTicks/1000; //milliseconds from Begin to End 39 this->elapSeconds = this->elapMilli/1000; //seconds from Begin to End 40 this->elapMinutes = this->elapSeconds/60; //minutes from Begin to End 41 } 42 };