Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / 07-Practice-05.04.2022 / GameCase.cpp
diff options
context:
space:
mode:
Commit6ec95b5d689aa38b373ef948ba67ba59235c0eb9 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-06 10:50:30 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-04-06 10:50:30 +0300
Files888b5a8545dd6ce3ca02233f16fafed7f0861cc1 /Year 1/Object-oriented Programming/07-Practice-05.04.2022/GameCase.cpp
uni-projects-6ec95b5d689aa38b373ef948ba67ba59235c0eb9.tar
uni-projects-6ec95b5d689aa38b373ef948ba67ba59235c0eb9.tar.gz
uni-projects-6ec95b5d689aa38b373ef948ba67ba59235c0eb9.zip
Parent30420a6ea65aa58389b9ffa0ba67130de376c079 (diff)
Added GameCase descriptions and a printing function for them
1 files changed, 44 insertions, 2 deletions
-rw-r--r--Year 1/Object-oriented Programming/07-Practice-05.04.2022/GameCase.cpp46
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);
}