-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
129 lines (119 loc) · 4.76 KB
/
main.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#define _CRTDBG_MAP_ALLOC
#include <string.h>
#include "time.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include "stocksystem.h"
using namespace std;
void PrintMenu();
int main() {
int choice = 0;
string inputchoice;
int asku;
string inputasku;
string adesc;
double aprice;
string inputaprice;
int amount;
string inputamt;
string ctlg = "";
StockSystem mystore;
while (choice != 8) {
PrintMenu();
// get the menu choice from standard input
getline(cin, inputchoice);
choice = atoi(inputchoice.c_str());
switch (choice) {
case 1: // Print balance
cout << "Funds: $" << mystore.GetBalance() << endl << endl;
break;
case 2: // Print catalogue
ctlg = mystore.GetCatalogue();
cout << ctlg << endl;
break;
case 3: // Add SKU
cout << "Enter a numeric SKU (will be converted to 5 digits): ";
getline(cin, inputasku);
asku = atoi(inputasku.c_str());
cout << "Enter item description: ";
getline(cin, adesc);
cout << "Enter a retail price: $";
getline(cin, inputaprice);
aprice = atof(inputaprice.c_str());
if (mystore.StockNewItem(StockItem(asku, adesc, aprice)))
cout << "Successfully added item to catalogue." << endl;
else
cout << "Item not added to catalogue." << endl;
break;
case 4: // Edit item description
cout << "Enter a numeric SKU to edit: ";
getline(cin, inputasku);
asku = atoi(inputasku.c_str());
cout << "Enter item description: ";
getline(cin, adesc);
if (mystore.EditStockItemDescription(asku, adesc))
cout << "Item successfully updated." << endl;
else
cout << "Item not updated." << endl;
break;
case 5: // Edit item price
cout << "Enter a numeric SKU to edit: ";
getline(cin, inputasku);
asku = atoi(inputasku.c_str());
cout << "Enter a retail price: $";
getline(cin, inputaprice);
aprice = atof(inputaprice.c_str());
if (mystore.EditStockItemPrice(asku, aprice))
cout << "Item successfully updated." << endl;
else
cout << "Item not updated." << endl;
break;
case 6: // Restock an item
cout << "Enter a numeric SKU to purchase: ";
getline(cin, inputasku);
asku = atoi(inputasku.c_str());
cout << "Enter a quantity to purchase: ";
getline(cin, inputamt);
amount = atoi(inputamt.c_str());
cout << "Enter the per-unit purchase price: $";
getline(cin, inputaprice);
aprice = atof(inputaprice.c_str());
if (mystore.Restock(asku, amount, aprice))
cout << "Item successfully restocked." << endl;
else
cout << "Item not restocked." << endl;
break;
case 7: // Sell an item
cout << "Enter the SKU of item to sell: ";
getline(cin, inputasku);
asku = atoi(inputasku.c_str());
cout << "Enter a quantity to sell: ";
getline(cin, inputamt);
amount = atoi(inputamt.c_str());
if (mystore.Sell(asku, amount))
cout << "Transaction complete. Have a nice day." << endl;
else
cout << "Item is out of stock. Sorry!" << endl;
break;
case 8: // Quit
// no need to do anything, will cause while loop to break
break;
default:
cout << "Invalid choice." << endl;
break;
}
}
return 0;
}
void PrintMenu() {
cout << "****************************************************\n"
<< "* Please select an option: *\n"
<< "* 1. Print balance 6. Restock an item *\n"
<< "* 2. Print catalogue 7. Sell an item *\n"
<< "* 3. Add a new SKU *\n"
<< "* 4. Edit item description *\n"
<< "* 5. Edit item price 8. Quit *\n"
<< "****************************************************\n" << endl;
cout << "Enter your choice: ";
}