paranid5

Students

Jun 25th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #ifndef _STUDENT_H_
  2. #define _STUDENT_H_
  3.  
  4. typedef unsigned u ;
  5.  
  6. class Student
  7. {
  8.  public:
  9.     virtual u exercise() = 0;
  10.     virtual ~Student() = 0;
  11. };
  12.  
  13. class Boy : public Student
  14. {
  15.  public:
  16.     u exercise() override;
  17.     ~Boy() override;
  18. };
  19.  
  20. class NotBoy : public Student
  21. {
  22.  public:
  23.     u exercise() override;
  24.     ~NotBoy() override;
  25. };
  26.  
  27.  
  28. #endif//_STUDENT_H_
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. #include "student.h"
  37. #include <cstdlib>
  38. #include <ctime>
  39. #include <cstdio>
  40.  
  41. Student::~Student()
  42. = default;
  43.  
  44. u Boy::exercise ( )
  45. {
  46.     const u x = std::rand() % (20 - 15 + 1) + 15;
  47.     std::printf("I've done %u push-ups\n", x);
  48.     return x;
  49. }
  50. Boy::~Boy()
  51. = default;
  52.  
  53. u NotBoy::exercise ( )
  54. {
  55.     const u x = std::rand() % (20 - 15 + 1) + 15;
  56.     std::printf("I've done %u squats\n", x);
  57.     return x;
  58. }
  59. NotBoy::~NotBoy()
  60. = default;
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. #include "student.h"
  70. #include <cstdlib>
  71. #include <ctime>
  72. #include <cstdio>
  73.  
  74. int main ( )
  75. {
  76.     srand(time(nullptr));
  77.     u amount = 0;
  78.     for(u i = 0; i < 25; i++)
  79.     {
  80.         Student* a;
  81.         const u x = rand() % (1 - 0 + 1) + 0;
  82.         x == 0 ? a = new Boy : a = new NotBoy;
  83.         if(a -> exercise() >= 20) amount++;
  84.         delete a;
  85.     }
  86.     std::printf("%d students passed test", amount);
  87.     return 0;
  88. }
Add Comment
Please, Sign In to add comment