Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / task1 / Drinks / Drink.cpp
diff options
context:
space:
mode:
Commitbe9dc71f94c40127657723e2881b9929c297a736 (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-05-14 14:21:20 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-05-14 14:21:20 +0300
Filesf94484f124775ad7e0bbf25da75ccf2bd84ba33b /Sem. 12/task1/Drinks/Drink.cpp
Object-oriented_programming_FMI-be9dc71f94c40127657723e2881b9929c297a736.tar
Object-oriented_programming_FMI-be9dc71f94c40127657723e2881b9929c297a736.tar.gz
Object-oriented_programming_FMI-be9dc71f94c40127657723e2881b9929c297a736.zip
Parentf8ddb55bb214bcf39a0383f7556ff1a8a00560ac (diff)
sem 12
1 files changed, 68 insertions, 0 deletions
-rw-r--r--Sem. 12/task1/Drinks/Drink.cpp68
diff --git a/Sem. 12/task1/Drinks/Drink.cpp b/Sem. 12/task1/Drinks/Drink.cpp
new file mode 100644
index 0000000..6f41b55
--- /dev/null
+++ b/Sem. 12/task1/Drinks/Drink.cpp
@@ -0,0 +1,68 @@
+#include "Drink.h"
+#include <iostream>
+
+Drink::Drink() : Drink("Unknown", 0)
+{}
+const char* Drink::getName() const
+{
+ return name;
+}
+int Drink::getMl() const
+{
+ return ml;
+}
+
+void Drink::setName(const char* name)
+{
+ delete[] this->name;
+
+ this->name = new char[strlen(name) + 1];
+ strcpy(this->name, name);
+
+}
+void Drink::setMl(int ml)
+{
+ const int MAX_ML = 1000;
+ const int MIN_ML = 100;
+
+ ml = MIN_ML;
+ if (MIN_ML <= ml && ml <= MAX_ML)
+ this->ml = ml;
+
+}
+
+Drink::Drink(const char* name, int ml) : name(nullptr)
+{
+ setName(name);
+ setMl(ml);
+}
+
+Drink::Drink(const Drink& other)
+{
+ copyFrom(other);
+}
+Drink& Drink::operator = (const Drink& other)
+{
+ if (this != &other)
+ {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+Drink::~Drink()
+{
+ free();
+}
+void Drink::copyFrom(const Drink& other)
+{
+ name = new char[strlen(other.name) + 1];
+ strcpy(name, other.name);
+
+ ml = other.ml;
+}
+void Drink::free()
+{
+ delete[] name;
+ ml = 0;
+} \ No newline at end of file