Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Store.h"
- Store::Store()
- {
- this->products = nullptr;
- this->size = 0;
- this->capacity = 5;
- }
- Store::Store(const Store& other)
- {
- this->copy(other);
- }
- const Product* Store::getProducts()const
- {
- return this->products;
- }
- int Store::getSize() const
- {
- return this->size;
- }
- int Store::getCapacity() const
- {
- return this->capacity;
- }
- Store& Store::operator=(const Store& other)
- {
- if (this != &other)
- {
- this->erase();
- this->copy(other);
- }
- return *this;
- }
- void Store::Add(const Product p1)
- {
- if (this->size >= this->capacity)
- {
- std::cout << "No more space for more products!\n\n";
- return;
- }
- Product* BiggerBuffer = new Product[this->size + 1];
- for (int i = 0; i < this->size; i++)
- {
- BiggerBuffer[i + 1] = this->products[i];
- }
- BiggerBuffer[0] = p1;
- this->size++;
- this->erase();
- this->products = BiggerBuffer;
- }
- void Store::Delete(int index)
- {
- if (this->size <= 0)
- {
- std::cout << "The store is empty!\n\n";
- return;
- }
- Product* smallerBuffer = new Product[this->size - 1];
- int nextIndex = 0;
- for (int i = 0; i < index - 1; i++)
- {
- smallerBuffer[i] = this->products[i];
- nextIndex++;
- }
- int n = this->size - index;
- for (int i = 0; i < n; i++)
- {
- smallerBuffer[nextIndex + i] = this->products[index + i];
- }
- this->erase();
- this->size--;
- this->products = smallerBuffer;
- }
- void Store::Change(int index, int SKU, const char* brand, const char* model, const char* category, const char* colour, double size, double price, int count)
- {
- products[index - 1].setProduct(SKU, brand, model, category, colour, size, price, count);
- }
- void Store::printProducts()const
- {
- if (this->size <= 0)
- {
- std::cout << "The store is empty!\n\n";
- return;
- }
- for (int i = 0; i < size; i++)
- {
- std::cout << "::PRODUCT " << i + 1 << "::\n";
- products[i].printProduct();
- std::cout << "\n";
- }
- }
- void Store::printAvaibleProducts()const
- {
- if (this->size <= 0)
- {
- std::cout << "The store is empty!\n\n";
- return;
- }
- int count = 0;
- for (int i = 0; i < size; i++)
- {
- if (products[i].getCount() > 0)
- {
- std::cout << "::PRODUCT " << i + 1 << "::\n";
- products[i].printProduct();
- std::cout << "\n";
- count++;
- }
- }
- if (count == 0)
- {
- std::cout << "We need to restock the store :( !\n\n";
- }
- }
- Store::~Store()
- {
- this->erase();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement