diff options
clean up
10 files changed, 0 insertions, 462 deletions
| -rw-r--r-- | Sem. 12/task1/Bar/Bar.cpp | 45 | ||||
| -rw-r--r-- | Sem. 12/task1/Bar/Bar.h | 36 | ||||
| -rw-r--r-- | Sem. 12/task1/Drinks/AlcoholDrink.cpp | 24 | ||||
| -rw-r--r-- | Sem. 12/task1/Drinks/AlcoholDrink.h | 15 | ||||
| -rw-r--r-- | Sem. 12/task1/Drinks/Drink.cpp | 69 | ||||
| -rw-r--r-- | Sem. 12/task1/Drinks/Drink.h | 27 | ||||
| -rw-r--r-- | Sem. 12/task1/Drinks/EnergyDrink.cpp | 49 | ||||
| -rw-r--r-- | Sem. 12/task1/Drinks/EnergyDrink.h | 22 | ||||
| -rw-r--r-- | Sem. 12/task1/Queue/Queue.hpp | 145 | ||||
| -rw-r--r-- | Sem. 12/task1/main.cpp | 30 |
diff --git a/Sem. 12/task1/Bar/Bar.cpp b/Sem. 12/task1/Bar/Bar.cpp deleted file mode 100644 index 0235801..0000000 --- a/Sem. 12/task1/Bar/Bar.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "Bar.h" - -void Bar::addDrink(const char* name, int ml) -{ - drinks.enqueue(Drink(name, ml)); -} -void Bar::addAlocoholDrink(const char* name, int ml, int alcohol) -{ - alcoholDrinks.enqueue(AlcoholDrink(name, ml, alcohol)); -} - -Drink Bar::getDrink() -{ - Drink d = drinks.dequeue(); - incrementStatistics(d); - return d; -} -AlcoholDrink Bar::getAcloholDrink() -{ - AlcoholDrink d = alcoholDrinks.dequeue(); - incrementStatistics(d, true); - return d; -} - -void Bar::incrementStatistics(const Drink& dr, bool isAlcoholDrink) -{ - stats.mlSold += dr.getMl(); - stats.allDrinksSold++; - - if (isAlcoholDrink) - stats.alcoholDrinksSold++; -} - -size_t Bar::getMlSold() const -{ - return stats.mlSold; -} -size_t Bar::getAllDrinksSold() const -{ - return stats.allDrinksSold; -} -size_t Bar::getAlcoholDrinksSold() const -{ - return stats.alcoholDrinksSold; -} diff --git a/Sem. 12/task1/Bar/Bar.h b/Sem. 12/task1/Bar/Bar.h deleted file mode 100644 index 06e7d92..0000000 --- a/Sem. 12/task1/Bar/Bar.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include <iostream> -#include "../Drinks/AlcoholDrink.h" -#include "../Queue/Queue.hpp" - - - -class Bar -{ - struct Statistics - { - size_t mlSold = 0; - size_t allDrinksSold = 0; - size_t alcoholDrinksSold = 0; - }; - -private: - Queue<Drink> drinks; - Queue<AlcoholDrink> alcoholDrinks; - - Statistics stats; - - void incrementStatistics(const Drink& dr, bool isAlcoholDrink = false); - -public: - - void addDrink(const char* name, int ml); - void addAlocoholDrink(const char* name, int ml, int alcohol); - - Drink getDrink(); - AlcoholDrink getAcloholDrink(); - - size_t getMlSold() const; - size_t getAllDrinksSold() const; - size_t getAlcoholDrinksSold() const; -}; diff --git a/Sem. 12/task1/Drinks/AlcoholDrink.cpp b/Sem. 12/task1/Drinks/AlcoholDrink.cpp deleted file mode 100644 index 4171ff0..0000000 --- a/Sem. 12/task1/Drinks/AlcoholDrink.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma warning(disable: 4996) -#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 deleted file mode 100644 index 89b2da3..0000000 --- a/Sem. 12/task1/Drinks/AlcoholDrink.h +++ /dev/null @@ -1,15 +0,0 @@ -#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 deleted file mode 100644 index 55b3e3a..0000000 --- a/Sem. 12/task1/Drinks/Drink.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#pragma warning(disable: 4996) -#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 deleted file mode 100644 index d4d37ae..0000000 --- a/Sem. 12/task1/Drinks/Drink.h +++ /dev/null @@ -1,27 +0,0 @@ -#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 deleted file mode 100644 index ef61456..0000000 --- a/Sem. 12/task1/Drinks/EnergyDrink.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma warning(disable: 4996) -#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 deleted file mode 100644 index 99bbbdb..0000000 --- a/Sem. 12/task1/Drinks/EnergyDrink.h +++ /dev/null @@ -1,22 +0,0 @@ -// име, мл, сертификат за качество. -#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 diff --git a/Sem. 12/task1/Queue/Queue.hpp b/Sem. 12/task1/Queue/Queue.hpp deleted file mode 100644 index e47460a..0000000 --- a/Sem. 12/task1/Queue/Queue.hpp +++ /dev/null @@ -1,145 +0,0 @@ -#pragma once -#include <iostream> - -template <typename T> -class Queue -{ - T* data; - size_t capacity; - size_t count; - - size_t head; //where to get - size_t tail; //last added element; - - void resize(size_t newCapacity); - - void copyFrom(const Queue<T>& other); - void free(); -public: - Queue(); - - Queue(const Queue<T>& other); - Queue<T>& operator=(const Queue<T>& other); - - void enqueue(const T& obj); - T dequeue(); - - size_t getCount(); - size_t isEmpty(); - - ~Queue(); -}; - -template <typename T> -Queue<T>::Queue() -{ - capacity = 4; - data = new T[capacity]; - - count = 0; - head = tail = 0; -} - - - -template <typename T> -void Queue<T>::enqueue(const T& obj) -{ - if (count == capacity) - resize(capacity * 2); - if (count != 0) - tail++; - - tail %= capacity; //so we don't get an out of range exception - - data[tail] = obj; - - count++; -} - -template <typename T> -T Queue<T>::dequeue() -{ - if (count == 0) - throw std::exception("The collection is empty!"); - - T toReturn = data[head]; - (++head) %= capacity; - - count--; - - return toReturn; -} - -template <typename T> -size_t Queue<T>::getCount() -{ - return count; -} - -template <typename T> -size_t Queue<T>::isEmpty() -{ - return getCount() == 0; -} - -template <typename T> -void Queue<T>::resize(size_t newCapacity) -{ - T* newData = new T[newCapacity]; - - for (int i = 0, ind = head; i < count; i++, (++ind) %= capacity) - newData[i] = data[ind]; - - delete[] data; - capacity = newCapacity; - data = newData; - - head = 0; - tail = count - 1; -} - -template <typename T> -void Queue<T>::copyFrom(const Queue<T>& other) -{ - data = new T[other.capacity]; - for (int i = 0; i < other.capacity; i++) - data[i] = other.data[i]; - - head = other.head; - tail = other.tail; - - count = other.count; - capacity = other.capacity; - -} - -template <typename T> -void Queue<T>::free() -{ - delete[] data; -} - -template <typename T> -Queue<T>::Queue(const Queue<T>& other) -{ - copyFrom(other); - -} - -template <typename T> -Queue<T>& Queue<T>::operator=(const Queue<T>& other) -{ - if (this != &other) - { - free(); - copyFrom(other); - } - return *this; -} - -template <typename T> -Queue<T>::~Queue() -{ - free(); -} diff --git a/Sem. 12/task1/main.cpp b/Sem. 12/task1/main.cpp deleted file mode 100644 index ba367d8..0000000 --- a/Sem. 12/task1/main.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma warning(disable: 4996) - - -#include <iostream> -#include "Bar/Bar.h" -#include "Drinks/EnergyDrink.h" - -using namespace std; - -int main() -{ - Bar b; - - b.addDrink("Coke", 330); - - b.addDrink("Fanta", 500); - - b.addAlocoholDrink("Zagorka", 500, 5); - - cout << b.getDrink().getName()<<endl; - cout << b.getDrink().getName() << endl; - - cout << b.getAcloholDrink().getName() << endl; - - cout << b.getAllDrinksSold() << endl; - - EnergyDrink energyDrink("Monster", 500, "ECAS"); - - std::cout << energyDrink.getCertifiate(); -} |
