forked from furkankirac/cs321-2019-20-fall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek5-lab.cpp
71 lines (50 loc) · 1.3 KB
/
week5-lab.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
#include <iostream>
#include <vector>
#include <map>
// We may not ask for sell item for the moment.
enum class item_archetypes { drink, fruit, snack, tech, apparel };
struct Item
{
item_archetypes itemtype;
std::string item_name;
double price;
int id;
};
struct Bank{
double balance=0;
std::vector<double> transaction_hist;
void updateBalance(const double price){
transaction_hist.push_back(price);
balance += price;
}
};
class Store
{
private:
std::map<item_archetypes, std::vector<Item>> item_list;
Bank bank;
public:
void printStore(){
// Print archetype --> item names
// Bank information --> balance & transaction
}
void sellItem(Item item){
for( auto store_item : item_list[item.itemtype])
{
if(item.id == store_item.id){
bank.updateBalance(item.price);
}else
std::cout << "item not found!" << std::endl;
}
}
void buyItem(const Item item){
item_list[item.itemtype].push_back(item);
bank.updateBalance(item.price);
}
Store(Bank bank): bank{bank} {}
};
int main()
{
Item I{item_archetypes::drink, "coke", 5, 0};
return 0;
}