Advertisement
kolarov

list

Jun 26th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include "Shop.h"
  4. #include "Product.h"
  5. #include "Item.h"
  6. #include <list>
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11.  
  12.  
  13.  
  14.     list<Product*> cartList;
  15.     Shop *newShop = new Shop("Nov Magazin", "1234567890", "Kokalqne", 0, 0, 0);
  16.  
  17.     Product *newProduct = new Product("Carevica", "1111111111", true, 12, true, 123);
  18.     newShop->setProduct(*newProduct);
  19.     Product *newProduct2 = new Product("Orange", "2222222222", true, 32, true, 123);
  20.     newShop->setProduct(*newProduct2);
  21.     float cartTotal = 0;
  22.     float money = 1000;
  23.  
  24.    
  25.  
  26.     printf("Please choose your option: \n\rEnter 'S' to shop customer info \n\rEnter 'A' to add new product in store\n\rEnter 'B' to find and add product in your cart\n\rEnter 'C' to clear your cart\n\rEnter 'T' to display total value\n\rEnter 'G' add amount of money\n\rEnter 'E' for exit \n\r");
  27.  
  28.     char index = 'n';
  29.  
  30.  
  31.     while (index != 'E') {
  32.  
  33.         cin >> index;
  34.  
  35.         switch (index)
  36.         {
  37.         case 'S':
  38.         {
  39.  
  40.             string name = newShop->getName();
  41.             string address = newShop->getAddress();
  42.             double purchases = newShop->getPurchases();
  43.             double given = newShop->getGiven();
  44.             double change = newShop->getChange();
  45.  
  46.             cout << name << endl;
  47.             cout << "Address :" << address << endl;
  48.             cout << "Address :" << address << endl;
  49.             cout << "Purchases :" << purchases << endl;
  50.             cout << "Given :" << given << endl;
  51.             cout << "Change :" << change << endl;
  52.  
  53.             break;
  54.         }
  55.  
  56.         case 'A':
  57.         {
  58.  
  59.  
  60.             string name;
  61.             string code;
  62.             string avaliable;
  63.             float price;
  64.             string forEating;
  65.             int amount;
  66.  
  67.             cout << "Name :";
  68.             cin >> name;
  69.             cout << "BIC :";
  70.             cin >> code;
  71.             cout << "1 for true others for false: ";
  72.             cin >> avaliable;
  73.             cout << "Price";
  74.             cin >> (float)price;
  75.             cout << "1 for true others for false: ";
  76.             cin >> forEating;
  77.             cout << "Amout :";
  78.             cin >> (int)amount;
  79.  
  80.             bool av = false;
  81.             bool eat = false;
  82.  
  83.             if (avaliable == "1") {
  84.                 av = true;
  85.             }
  86.  
  87.  
  88.             if (forEating == "1") {
  89.                 eat = true;
  90.             }
  91.             Product *newProduct = new Product(name, code, av, price, eat, amount);
  92.             newShop->setProduct(*newProduct);
  93.             cout << "Your product is added try another option." << endl;
  94.             break;
  95.         }
  96.         case 'B': {
  97.  
  98.             string code;
  99.             cout << "Enter 10 digit product code" << endl;
  100.             cin >> code;
  101.  
  102.             list<Product*> productlist = newShop->getProducts();
  103.             list<Product*>::iterator it;
  104.             int check = true;
  105.  
  106.             for (it = productlist.begin(); it != productlist.end(); it++)
  107.             {
  108.                 string currentStudentId = (*it)->getCode();
  109.  
  110.  
  111.                 //check for money
  112.                 if (code == currentStudentId) {
  113.  
  114.                     Product *currentProduct = *it;
  115.  
  116.                     cartTotal += (*it)->getPrice();
  117.  
  118.                     cartList.push_back(currentProduct);
  119.                     check = false;
  120.                     cout << "Added to cart" << endl;
  121.                 }
  122.             }
  123.  
  124.             if (check) {
  125.                 cout << "Product is not found" << endl;
  126.             }
  127.  
  128.             break;
  129.         }
  130.         case 'C': {
  131.        
  132.             cartTotal = 0;
  133.  
  134.  
  135.             list<Product*>::iterator it;
  136.  
  137.             for (it = cartList.begin(); it != cartList.end(); it++)
  138.             {
  139.                 cartList.erase(it);
  140.             }
  141.  
  142.             break;
  143.         }
  144.         default:
  145.             break;
  146.         }
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement