-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStore.cpp
More file actions
88 lines (76 loc) · 1.82 KB
/
Store.cpp
File metadata and controls
88 lines (76 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Store.h"
#include "Store.h"
#include "Client.h"
#include <iostream>
using namespace std;
Store::Store()
{
}
Store::Store(Client client)
{
_client = client;
}
void Store::start(Client client)
{
_client = client;
Inventory inventory;
int i;
int j;
string choice;
std::cout << " ANN TAYLOR " << endl
<< endl;
for (i = 0, j = 1; i <= 9; i++, j++)
{
std::cout << j << ". " << inventory.getProducts(i).getName() << " " << inventory.getProducts(i).getPrice() << endl;
}
std::cout << "Press 'N' if you want to get out of the store" << endl;
std::cout << "Choose a product to add to cart: ";
std::cin >> choice;
std::cout << endl;
while (choice != "N")
{
Product selectedProduct = inventory.getProducts(stoi(choice) - 1);
std::cout << "Selected " << selectedProduct.getName() << endl
<< selectedProduct.getStock() << " in stock." << endl
<< endl;
if (selectedProduct.getStock() > 0)
{
string selectedPayment;
std::cout << "PAYMENT METHOD" << endl
<< endl;
std::cout << "1. Credit Card" << endl
<< "2. Gift Card" << endl
<< endl;
std::cin >> selectedPayment;
std::cout << endl;
float productPrice = selectedProduct.getPrice();
if (selectedPayment == "1")
{
if (_client.getCreditCard().discount(productPrice))
{
inventory.reduceStock(stoi(choice) - 1);
}
break;
}
else if (selectedPayment == "2")
{
if (_client.getgiftCard().discount(productPrice))
{
inventory.reduceStock(stoi(choice) - 1);
}
break;
}
}
else
{
std::cout << "Sorry, it seems that we are out of stock!" << endl;
}
std::cout
<< endl
<< "Press 'N' if you want to finish the purchase" << endl;
std::cout << "Choose other product to add to cart: ";
choice;
std::cin >> choice;
std::cout << endl;
}
}