Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 1st, 2020 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Store.h"
  2.  
  3.  
  4. Store::Store()
  5. {
  6.     this->products = nullptr;
  7.     this->size = 0;
  8.     this->capacity = 5;
  9. }
  10.  
  11. Store::Store(const Store& other)
  12. {
  13.     this->copy(other);
  14. }
  15.  
  16. const Product* Store::getProducts()const
  17. {
  18.     return this->products;
  19. }
  20.  
  21. int Store::getSize() const
  22. {
  23.     return this->size;
  24. }
  25.  
  26. int Store::getCapacity() const
  27. {
  28.     return this->capacity;
  29. }
  30.  
  31.  
  32. Store& Store::operator=(const Store& other)
  33. {
  34.     if (this != &other)
  35.     {
  36.         this->erase();
  37.         this->copy(other);
  38.     }
  39.  
  40.     return *this;
  41. }
  42.  
  43. void Store::Add(const Product p1)
  44. {
  45.  
  46.     if (this->size >= this->capacity)
  47.     {
  48.         std::cout << "No more space for more products!\n\n";
  49.         return;
  50.     }
  51.  
  52.  
  53.     Product* BiggerBuffer = new Product[this->size + 1];
  54.     for (int i = 0; i < this->size; i++)
  55.     {
  56.         BiggerBuffer[i + 1] = this->products[i];
  57.     }
  58.     BiggerBuffer[0] = p1;
  59.     this->size++;
  60.     this->erase();
  61.     this->products = BiggerBuffer;
  62.  
  63. }
  64.  
  65. void Store::Delete(int index)
  66. {
  67.     if (this->size <= 0)
  68.     {
  69.         std::cout << "The store is empty!\n\n";
  70.         return;
  71.     }
  72.     Product* smallerBuffer = new Product[this->size - 1];
  73.  
  74.     int nextIndex = 0;
  75.  
  76.     for (int i = 0; i < index - 1; i++)
  77.     {
  78.         smallerBuffer[i] = this->products[i];
  79.         nextIndex++;
  80.     }
  81.     int n = this->size - index;
  82.     for (int i = 0; i < n; i++)
  83.     {
  84.         smallerBuffer[nextIndex + i] = this->products[index + i];
  85.     }
  86.     this->erase();
  87.     this->size--;
  88.     this->products = smallerBuffer;
  89. }
  90.  
  91. 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)
  92. {
  93.     products[index - 1].setProduct(SKU, brand, model, category, colour, size, price, count);
  94. }
  95.  
  96. void Store::printProducts()const
  97. {
  98.     if (this->size <= 0)
  99.     {
  100.         std::cout << "The store is empty!\n\n";
  101.         return;
  102.     }
  103.     for (int i = 0; i < size; i++)
  104.     {
  105.         std::cout << "::PRODUCT " << i + 1 << "::\n";
  106.         products[i].printProduct();
  107.         std::cout << "\n";
  108.     }
  109. }
  110.  
  111. void Store::printAvaibleProducts()const
  112. {
  113.     if (this->size <= 0)
  114.     {
  115.         std::cout << "The store is empty!\n\n";
  116.         return;
  117.     }
  118.     int count = 0;
  119.     for (int i = 0; i < size; i++)
  120.     {
  121.         if (products[i].getCount() > 0)
  122.         {
  123.             std::cout << "::PRODUCT " << i + 1 << "::\n";
  124.             products[i].printProduct();
  125.             std::cout << "\n";
  126.             count++;
  127.         }
  128.     }
  129.     if (count == 0)
  130.     {
  131.         std::cout << "We need to restock the store :( !\n\n";
  132.     }
  133. }
  134.  
  135. Store::~Store()
  136. {
  137.     this->erase();
  138. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top