From 112a0d344da9e66d20ee9ab5d488e59c5d52e6ad Mon Sep 17 00:00:00 2001 From: Angeld55 Date: Thu, 9 Apr 2020 18:09:42 +0300 Subject: added new examples --- Big4_and_inheritance/Drinks/Drink.cpp | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Big4_and_inheritance/Drinks/Drink.cpp (limited to 'Big4_and_inheritance/Drinks/Drink.cpp') diff --git a/Big4_and_inheritance/Drinks/Drink.cpp b/Big4_and_inheritance/Drinks/Drink.cpp new file mode 100644 index 0000000..709446b --- /dev/null +++ b/Big4_and_inheritance/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; +} -- cgit v1.3.1-23-gd82d