Created
December 19, 2025 16:26
-
-
Save nicolekorch/679fc93cf8903997aaa371f23567b22b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| class Obstacle; | |
| class Participant { | |
| protected: | |
| string name; | |
| int maxRun; | |
| int maxJump; | |
| public: | |
| Participant(string n, int r, int j) : name(n), maxRun(r), maxJump(j) {} | |
| virtual bool run(int distance) { | |
| if (distance <= maxRun) { | |
| cout << "Учасник[" << name << "] пробіг доріжку на дистанції[" << distance << "]\n"; | |
| return true; | |
| } | |
| cout << "Учасник[" << name << "] не пройшов перешкоду[Бігова доріжка] на дистанції[" << distance << "]. Пройдено[" << maxRun << "]\n"; | |
| return false; | |
| } | |
| virtual bool jump(int height) { | |
| if (height <= maxJump) { | |
| cout << "Учасник[" << name << "] перестрибнув стіну на висоті[" << height << "]\n"; | |
| return true; | |
| } | |
| cout << "Учасник[" << name << "] не пройшов перешкоду[Стіна] на дистанції[" << height << "]. Пройдено[" << maxJump << "]\n"; | |
| return false; | |
| } | |
| string getName() { return name; } | |
| }; | |
| class Human : public Participant { | |
| public: | |
| Human(string n) : Participant(n, 500, 2) {} | |
| }; | |
| class Cat : public Participant { | |
| public: | |
| Cat(string n) : Participant(n, 300, 5) {} | |
| }; | |
| class Robot : public Participant { | |
| public: | |
| Robot(string n) : Participant(n, 1000, 1) {} | |
| }; | |
| class Obstacle { | |
| public: | |
| virtual bool overcome(Participant* p) = 0; | |
| }; | |
| class Track : public Obstacle { | |
| int length; | |
| public: | |
| Track(int l) : length(l) {} | |
| bool overcome(Participant* p) { | |
| return p->run(length); | |
| } | |
| }; | |
| class Wall : public Obstacle { | |
| int height; | |
| public: | |
| Wall(int h) : height(h) {} | |
| bool overcome(Participant* p) { | |
| return p->jump(height); | |
| } | |
| }; | |
| int main() { | |
| vector<Participant*> participants = { | |
| new Human("Олег"), | |
| new Cat("Барсик"), | |
| new Robot("R2D2") | |
| }; | |
| vector<Obstacle*> obstacles = { | |
| new Track(200), | |
| new Wall(2), | |
| new Track(600), | |
| new Wall(4) | |
| }; | |
| for (Participant* p : participants) { | |
| bool passed = true; | |
| for (Obstacle* o : obstacles) { | |
| if (!o->overcome(p)) { | |
| passed = false; | |
| break; | |
| } | |
| } | |
| cout << "-------------------------\n"; | |
| } | |
| for (auto p : participants) delete p; | |
| for (auto o : obstacles) delete o; | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
курсовая