Website Summary Files Commits Branches @commit @diff @stats
path: root / Big4_and_inheritance / Drinks
diff options
context:
space:
mode:
Commit112a0d344da9e66d20ee9ab5d488e59c5d52e6ad (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2020-04-09 18:09:42 +0300
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2020-04-09 18:09:42 +0300
Filese3bb9cf17c24a3b53c746d9142906d550d549465 /Big4_and_inheritance/Drinks
Object-oriented_programming_FMI-112a0d344da9e66d20ee9ab5d488e59c5d52e6ad.tar
Object-oriented_programming_FMI-112a0d344da9e66d20ee9ab5d488e59c5d52e6ad.tar.gz
Object-oriented_programming_FMI-112a0d344da9e66d20ee9ab5d488e59c5d52e6ad.zip
Parentec26fab32d144b436d08f9da6049bd053156d783 (diff)
added new examples
diff --git a/Big4_and_inheritance/Drinks/AlcoholDrink.cpp b/Big4_and_inheritance/Drinks/AlcoholDrink.cpp
new file mode 100644
index 0000000..0e20087
--- /dev/null
+++ b/Big4_and_inheritance/Drinks/AlcoholDrink.cpp
@@ -0,0 +1,18 @@
+#include "AlcoholDrink.h"
+
+
+
+AlcoholDrink::AlcoholDrink(const char* mark, int ml, int percentAlcohol) : Drink(mark,ml)
+{
+ setAlcohol(percentAlcohol);
+}
+void AlcoholDrink::setAlcohol(int alcohol)
+{
+ if (alcohol < 4 || alcohol>98)
+ alcohol = 20;
+ percentAlcohol = alcohol;
+}
+int AlcoholDrink::getAlcohol() const
+{
+ return percentAlcohol;
+}
diff --git a/Big4_and_inheritance/Drinks/AlcoholDrink.h b/Big4_and_inheritance/Drinks/AlcoholDrink.h
new file mode 100644
index 0000000..0bd1d10
--- /dev/null
+++ b/Big4_and_inheritance/Drinks/AlcoholDrink.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include "Drink.h"
+
+class AlcoholDrink : public Drink
+{
+private:
+ int percentAlcohol;
+
+public:
+ AlcoholDrink(const char* mark, int ml, int percentAlcohol);
+ void setAlcohol(int alcohol);
+ int AlcoholDrink::getAlcohol() const;
+};
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;
+}
diff --git a/Big4_and_inheritance/Drinks/Drink.h b/Big4_and_inheritance/Drinks/Drink.h
new file mode 100644
index 0000000..db93c97
--- /dev/null
+++ b/Big4_and_inheritance/Drinks/Drink.h
@@ -0,0 +1,21 @@
+#pragma once
+#include <iostream>
+
+class Drink
+{
+private:
+ char* mark;
+ int ml;
+ void CopyFrom(const Drink& other);
+ void Free();
+public:
+ Drink();
+ Drink(const char* mark, int ml);
+ Drink(const Drink& other);
+ Drink& operator=(const Drink& other);
+ ~Drink();
+
+ void setML(int ml);
+ int getML() const;
+ const char* getMark() const;
+};
diff --git a/Big4_and_inheritance/Drinks/main.cpp b/Big4_and_inheritance/Drinks/main.cpp
new file mode 100644
index 0000000..c809123
--- /dev/null
+++ b/Big4_and_inheritance/Drinks/main.cpp
@@ -0,0 +1,10 @@
+#include "AlcoholDrink.h"
+int main()
+{
+ AlcoholDrink DR1("Spirt", 100, 98);
+
+ AlcoholDrink dr2 (DR1);
+ dr2.getMark();
+
+
+}