diff options
1 files changed, 44 insertions, 2 deletions
| -rw-r--r-- | Year 1/Object-oriented Programming/07-Practice-05.04.2022/GameCase.cpp | 46 |
diff --git a/Year 1/Object-oriented Programming/07-Practice-05.04.2022/GameCase.cpp b/Year 1/Object-oriented Programming/07-Practice-05.04.2022/GameCase.cpp index f16e72b..e0337a9 100644 --- a/Year 1/Object-oriented Programming/07-Practice-05.04.2022/GameCase.cpp +++ b/Year 1/Object-oriented Programming/07-Practice-05.04.2022/GameCase.cpp @@ -1,17 +1,59 @@ #include "GameCase.h" -GameCase::GameCase() : GameCase('\0', nullptr) +/* Private */ + +void GameCase::copyFrom(const GameCase& other) { + this->command = other.command; + this->description = new char[strlen(other.description) + 1]; + strcpy(this->description, other.description); + this->func = other.func; +} + +void GameCase::free() { + delete[] description; +} + +/* Public */ + +GameCase::GameCase() : GameCase('\0', nullptr, nullptr) {} -GameCase::GameCase(char command, bool func(double&)) { +GameCase::GameCase(char command, const char* description, bool func(double&)) { this->command = command; this->func = func; + + if (description == nullptr) + return; + + int descLen = strlen(description); + this->description = new char[descLen + 1]; + strcpy(this->description, description); +} + +GameCase::GameCase(const GameCase& other) { + this->copyFrom(other); +} + +GameCase& GameCase::operator=(const GameCase& other) { + if (this != &other) { + this->free(); + this->copyFrom(other); + } + return *this; +} + +GameCase::~GameCase() { + this->free(); } char GameCase::get_comm() const { return this->command; } +void GameCase::print() const { + std::cout << this->command << " - " << this->description << std::endl; +} + bool GameCase::exec(double& bet) const { return this->func(bet); } |
