Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _STUDENT_H_
- #define _STUDENT_H_
- typedef unsigned u ;
- class Student
- {
- public:
- virtual u exercise() = 0;
- virtual ~Student() = 0;
- };
- class Boy : public Student
- {
- public:
- u exercise() override;
- ~Boy() override;
- };
- class NotBoy : public Student
- {
- public:
- u exercise() override;
- ~NotBoy() override;
- };
- #endif//_STUDENT_H_
- #include "student.h"
- #include <cstdlib>
- #include <ctime>
- #include <cstdio>
- Student::~Student()
- = default;
- u Boy::exercise ( )
- {
- const u x = std::rand() % (20 - 15 + 1) + 15;
- std::printf("I've done %u push-ups\n", x);
- return x;
- }
- Boy::~Boy()
- = default;
- u NotBoy::exercise ( )
- {
- const u x = std::rand() % (20 - 15 + 1) + 15;
- std::printf("I've done %u squats\n", x);
- return x;
- }
- NotBoy::~NotBoy()
- = default;
- #include "student.h"
- #include <cstdlib>
- #include <ctime>
- #include <cstdio>
- int main ( )
- {
- srand(time(nullptr));
- u amount = 0;
- for(u i = 0; i < 25; i++)
- {
- Student* a;
- const u x = rand() % (1 - 0 + 1) + 0;
- x == 0 ? a = new Boy : a = new NotBoy;
- if(a -> exercise() >= 20) amount++;
- delete a;
- }
- std::printf("%d students passed test", amount);
- return 0;
- }
Add Comment
Please, Sign In to add comment