Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / task1 / Drinks
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
Object-oriented_programming_FMI-be9dc71f94c40127657723e2881b9929c297a736.tar
Object-oriented_programming_FMI-be9dc71f94c40127657723e2881b9929c297a736.tar.gz
Object-oriented_programming_FMI-be9dc71f94c40127657723e2881b9929c297a736.zip
Parentf8ddb55bb214bcf39a0383f7556ff1a8a00560ac (diff)
sem 12
diff --git a/Sem. 12/task1/Drinks/AlcoholDrink.cpp b/Sem. 12/task1/Drinks/AlcoholDrink.cpp
new file mode 100644
index 0000000..2f61087
--- /dev/null
+++ b/Sem. 12/task1/Drinks/AlcoholDrink.cpp
@@ -0,0 +1,23 @@
+#include "AlcoholDrink.h"
+
+AlcoholDrink::AlcoholDrink() : AlcoholDrink("Unknown", 0, 0){}
+
+AlcoholDrink::AlcoholDrink(const char* name, int ml, int alcoholPercentage) : Drink(name, ml)
+{
+ setAlcoholPercentage(alcoholPercentage);
+}
+int AlcoholDrink::getAlcoholPercentage() const
+{
+ return alcoholPercentage;
+}
+void AlcoholDrink::setAlcoholPercentage(int alcoholPercentage)
+{
+ const int MINPERCENTAGE = 1;
+ const int MAXPERCENTAGE = 97;
+
+ this->alcoholPercentage = MINPERCENTAGE;
+
+ if (MINPERCENTAGE <= alcoholPercentage && alcoholPercentage <= MAXPERCENTAGE)
+ this->alcoholPercentage = alcoholPercentage;
+
+} \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/AlcoholDrink.h b/Sem. 12/task1/Drinks/AlcoholDrink.h
new file mode 100644
index 0000000..89b2da3
--- /dev/null
+++ b/Sem. 12/task1/Drinks/AlcoholDrink.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "Drink.h"
+
+class AlcoholDrink : public Drink
+{
+ int alcoholPercentage;
+
+public:
+ AlcoholDrink();
+ AlcoholDrink(const char* name, int ml, int alcoholPercentage);
+
+ int getAlcoholPercentage() const;
+ void setAlcoholPercentage(int alcoholPercentage);
+}; \ No newline at end of file
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
diff --git a/Sem. 12/task1/Drinks/Drink.h b/Sem. 12/task1/Drinks/Drink.h
new file mode 100644
index 0000000..d4d37ae
--- /dev/null
+++ b/Sem. 12/task1/Drinks/Drink.h
@@ -0,0 +1,27 @@
+#pragma once
+
+class Drink
+{
+public:
+ Drink();
+
+ Drink(const char* name, int ml);
+
+ Drink(const Drink& other);
+ Drink& operator=(const Drink& other);
+ ~Drink();
+
+ const char* getName() const;
+ int getMl() const;
+
+ void setName(const char* name);
+ void setMl(int ml);
+
+private:
+ char* name;
+ int ml;
+
+ void copyFrom(const Drink& other);
+ void free();
+
+}; \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/EnergyDrink.cpp b/Sem. 12/task1/Drinks/EnergyDrink.cpp
new file mode 100644
index 0000000..a8ffac5
--- /dev/null
+++ b/Sem. 12/task1/Drinks/EnergyDrink.cpp
@@ -0,0 +1,48 @@
+#include "EnergyDrink.h"
+#include <iostream>
+
+EnergyDrink::EnergyDrink(const char* name, int ml, const char* sertificate) : Drink(name, ml), qualityCertificate(nullptr)
+{
+ setCertificate(sertificate);
+}
+const char* EnergyDrink::getCertifiate() const
+{
+ return qualityCertificate;
+}
+void EnergyDrink::setCertificate(const char* certficate)
+{
+ delete[] qualityCertificate;
+
+ qualityCertificate = new char[strlen(certficate) + 1];
+ strcpy(qualityCertificate, certficate);
+
+}
+EnergyDrink::EnergyDrink(const EnergyDrink& other) : Drink(other)
+{
+ copyFrom(other);
+}
+
+EnergyDrink& EnergyDrink::operator=(const EnergyDrink& other)
+{
+ if (this != &other)
+ {
+ Drink::operator=(other);
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+
+EnergyDrink::~EnergyDrink()
+{
+ free();
+}
+void EnergyDrink::copyFrom(const EnergyDrink& other)
+{
+ qualityCertificate = new char[strlen(other.qualityCertificate) + 1];
+ strcpy(qualityCertificate, other.qualityCertificate);
+}
+void EnergyDrink::free()
+{
+ delete[] qualityCertificate;
+} \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/EnergyDrink.h b/Sem. 12/task1/Drinks/EnergyDrink.h
new file mode 100644
index 0000000..99bbbdb
--- /dev/null
+++ b/Sem. 12/task1/Drinks/EnergyDrink.h
@@ -0,0 +1,22 @@
+// име, мл, сертификат за качество.
+#pragma once
+#include "Drink.h"
+
+class EnergyDrink : public Drink
+{
+private:
+ char* qualityCertificate;
+
+ void copyFrom(const EnergyDrink& other);
+ void free();
+
+public:
+ EnergyDrink(const char* name, int ml, const char* certificate);
+
+ EnergyDrink(const EnergyDrink& other);
+ EnergyDrink& operator=(const EnergyDrink& other);
+ ~EnergyDrink();
+
+ const char* getCertifiate() const;
+ void setCertificate(const char* certificate);
+}; \ No newline at end of file