Created
January 12, 2026 19:56
-
-
Save m1irka/471c414fa5a1e0db61f1782fcc16cb7e 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 <string> | |
| #include <vector> | |
| using namespace std; | |
| // общий класс для участников | |
| class Participant { | |
| public: | |
| string name; | |
| int maxRun; | |
| int maxJump; | |
| Participant(string n, int r, int j) : name(n), maxRun(r), maxJump(j) {} | |
| bool run(int distance) { | |
| // проверяю может ли пробежать | |
| if (distance <= maxRun) { | |
| cout << "Participant[" << name << "] ran distance " << distance << endl; | |
| return true; | |
| } | |
| else { | |
| cout << "Participant[" << name << "] failed to run distance " << distance << endl; | |
| return false; | |
| } | |
| } | |
| bool jump(int height) { | |
| // тут проверка на прыжок | |
| if (height <= maxJump) { | |
| cout << "Participant[" << name << "] jumped over height " << height << endl; | |
| return true; | |
| } | |
| else { | |
| cout << "Participant[" << name << "] failed to jump over height " << height << endl; | |
| return false; | |
| } | |
| } | |
| }; | |
| // тут делаю человек, кот, робот | |
| class Human : public Participant { | |
| public: | |
| Human(string n, int r, int j) : Participant(n, r, j) {} | |
| }; | |
| class Cat : public Participant { | |
| public: | |
| Cat(string n, int r, int j) : Participant(n, r, j) {} | |
| }; | |
| class Robot : public Participant { | |
| public: | |
| Robot(string n, int r, int j) : Participant(n, r, j) {} | |
| }; | |
| // теперь класс для препятствий | |
| class Track { | |
| public: | |
| int length; | |
| Track(int l) : length(l) {} | |
| bool overcome(Participant& p) { | |
| // тут участник должен бежать | |
| return p.run(length); | |
| } | |
| }; | |
| class Wall { | |
| public: | |
| int height; | |
| Wall(int h) : height(h) {} | |
| bool overcome(Participant& p) { | |
| // тут участник должен прыгать | |
| return p.jump(height); | |
| } | |
| }; | |
| int main() { | |
| // массив участников | |
| vector<Participant*> participants; | |
| participants.push_back(new Human("Alex", 100, 2)); | |
| participants.push_back(new Cat("Barsik", 50, 5)); | |
| participants.push_back(new Robot("Walle2T", 200, 1)); | |
| // массив препятствий | |
| vector<Track> tracks; | |
| tracks.push_back(Track(60)); | |
| tracks.push_back(Track(150)); | |
| vector<Wall> walls; | |
| walls.push_back(Wall(3)); | |
| walls.push_back(Wall(5)); | |
| // тут каждый участник проходит все препятствия | |
| for (size_t i = 0; i < participants.size(); i++) { | |
| Participant* p = participants[i]; | |
| bool stillInGame = true; | |
| // сначала все дорожки | |
| for (size_t j = 0; j < tracks.size(); j++) { | |
| if (stillInGame) { | |
| if (!tracks[j].overcome(*p)) { | |
| stillInGame = false; | |
| cout << "Participant[" << p->name << "] dropped out of the competition" << endl; | |
| } | |
| } | |
| } | |
| // потом все стены | |
| for (size_t j = 0; j < walls.size(); j++) { | |
| if (stillInGame) { | |
| if (!walls[j].overcome(*p)) { | |
| stillInGame = false; | |
| cout << "Participant[" << p->name << "] dropped out of the competition" << endl; | |
| } | |
| } | |
| } | |
| } | |
| // очистка память | |
| for (size_t i = 0; i < participants.size(); i++) { | |
| delete participants[i]; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment