Website Summary Files Commits Branches @commit @diff @stats
path: root / Big4AndInheritance / Drinks
diff options
context:
space:
mode:
Commit183c356b4f87e0461af0f19284989edc9c8b8036 (patch)
Author
 Angeld55 <achi_d@abv.bg>
2019-09-20 14:57:31 +0300
Committer
 GitHub <noreply@github.com>
2019-09-20 14:57:31 +0300
Filesb6ab32a21b0bb0dd5ce1d4ad668c62c089747bd3 /Big4AndInheritance/Drinks
Object-oriented_programming_FMI-183c356b4f87e0461af0f19284989edc9c8b8036.tar
Object-oriented_programming_FMI-183c356b4f87e0461af0f19284989edc9c8b8036.tar.gz
Object-oriented_programming_FMI-183c356b4f87e0461af0f19284989edc9c8b8036.zip
Parentdbf344f3db803770b26c196273942909b0839816 (diff)
Rename Big4AndInheritance/Drink.cpp to Big4AndInheritance/Drinks/Drink.cpp
1 files changed, 63 insertions, 0 deletions
-rw-r--r--Big4AndInheritance/Drinks/Drink.cpp63
diff --git a/Big4AndInheritance/Drinks/Drink.cpp b/Big4AndInheritance/Drinks/Drink.cpp
new file mode 100644
index 0000000..a2933ad
--- /dev/null
+++ b/Big4AndInheritance/Drinks/Drink.cpp
@@ -0,0 +1,63 @@
+#include "Drink.h"
+
+
+void Drink::CopyFrom(const Drink& other)
+{
+ int len = strlen(other.mark);
+ mark = new char[len + 1];
+ strcpy(mark, other.mark);
+
+ ml = other.ml;
+}
+void Drink::Free()
+{
+ delete[] mark;
+ ml = 0;
+}
+
+Drink::Drink()
+{
+ mark = new char[6];
+ strcpy(mark, "Water");
+ ml = 500;
+}
+Drink::Drink(const char* mark, int ml)
+{
+ int len = strlen(mark);
+ this->mark = new char[len + 1];
+ strcpy(this->mark, mark);
+
+ 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::setML(int ml)
+{
+ if (ml < 100 || ml> 1000)
+ ml = 500;
+ this->ml = ml;
+}
+int Drink::getML() const
+{
+ return ml;
+}
+const char* Drink::getMark() const
+{
+ return mark;
+}