Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. void wait ( int seconds )
  5. {
  6. clock_t endwait;
  7. endwait = clock () + seconds * CLOCKS_PER_SEC ;
  8. while (clock() < endwait) {}
  9. }
  10.  
  11. class Timer
  12. {
  13. private:
  14. time_t value;
  15.  
  16. public:
  17. Timer() { value = time(NULL);};
  18. void add(int h, int m, int s);
  19. void show();
  20. };
  21.  
  22. void Timer::add(int h, int m, int s)
  23. {
  24. value -= s + m * 60 + h * 3600;
  25. }
  26.  
  27. void Timer::show()
  28. {
  29. std::cout << difftime(time(NULL), value);
  30. }
  31.  
  32. int main()
  33. {
  34. Timer T;
  35. T.add(0, 0, 30);
  36. wait(5);
  37. T.show();
  38.  
  39. return 0;
  40. }
Add Comment
Please, Sign In to add comment