Advertisement
CunningFox

Untitled

Nov 14th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3.  
  4. using namespace std;
  5.  
  6. class Cat
  7. {
  8. private:
  9.     int CatAge = 0;
  10.     int CatFood = 0;
  11.  
  12. public:
  13.     const void Die();
  14.     const int GetAge();
  15.  
  16.     void SetAge(int age);
  17. };
  18.  
  19. const void Cat::Die()
  20. {
  21.     printf("Кот сдох. Прожил: %d\n", GetAge());
  22. }
  23.  
  24. const int Cat::GetAge()
  25. {
  26.     return CatAge;
  27. }
  28.  
  29. void Cat::SetAge(int age)
  30. {
  31.     CatAge = age;
  32. }
  33.  
  34. int main()
  35. {
  36.     setlocale(LC_ALL, "rus");
  37.  
  38.     srand(time(NULL));
  39.  
  40.     unsigned int start_t = time(NULL);
  41.     unsigned int t = 0;
  42.  
  43.     Cat po;
  44.  
  45.     unsigned short int ticks = rand() % 60;
  46.  
  47.     printf("Кот должен прожить: %d\n", ticks);
  48.  
  49.     while(t < ticks)
  50.     {
  51.         t = time(NULL) - start_t;
  52.         po.SetAge(t);
  53.     };
  54.  
  55.     po.Die();
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement