-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
109 lines (101 loc) · 2.99 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
#include "myFunc.h"
enum commands
{
ADD = 1,
REMOVE,
SHOWSITE,
SHOWCART,
EXIT
};
using namespace std;
int main() {
map<string, int> myShop;
map<string, int> myCart;
int command = 0;
int productCount;
cout << "---Shop site---" << endl;
cout << "How many uniq products will be added to the site?:";
enterValue(productCount,1);
for (int i = 0; i < productCount; ++i)
addProductInShop(myShop);
while(command != EXIT)
{
system("cls");
cout << "---Shop---" << endl;
cout << "Valid command: '1' for add product in cart;" << endl;
cout << " '2' for remove product from cart;" << endl;
cout << " '3' for show total on site;" << endl;
cout << " '4' for show total on cart;" << endl;
cout << " '5' for exit." << endl;
cin.clear();
cout << "Enter command:";
cin >> command;
system("cls");
if(command == ADD)
{
cout << "---Add product in basket---" << endl;
try {
moveProduct(myShop,myCart);
cout << "-ok, product has been added to the cart!" << endl;
}
catch (const TooMuchCountError& e)
{
cout << e.what() << endl;
cout << "Total count:" << e.getTotal() << endl;
}
catch (const EmptyError& e)
{
cout << e.what() << endl;
}
catch (const WrongArticleError& e)
{
cout << e.what() << endl;
}
}
else if (command == REMOVE)
{
cout << "---Remove product---" << endl;
try
{
moveProduct(myCart, myShop);
cout << "-ok, product has been removed from the cart!" << endl;
}
catch (const TooMuchCountError& e)
{
cout << e.what() << endl;
cout << "Total count:" << e.getTotal() << endl;
}
catch (const EmptyError& e)
{
cout << e.what() << endl;
}
catch (const WrongArticleError& e)
{
cout << e.what() << endl;
}
}
else if (command == SHOWSITE)
{
cout << "---Total on site---" << endl;
for(const auto& c:myShop)
cout << "Article " << c.first << " count " << c.second << endl;
}
else if (command == SHOWCART)
{
cout << "---Total in basket---" << endl;
for(const auto& c:myCart)
cout << "Article " << c.first << " count " << c.second << endl;
}
else
{
cout << "Unknown command!" << endl;
cin.ignore();
cin.clear();
}
system("pause");
}
system("cls");
cout << "---Bye, bye!---" << endl;
system("pause");
return 0;
}