-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
240 lines (225 loc) · 6.01 KB
/
Copy pathmain.cpp
File metadata and controls
240 lines (225 loc) · 6.01 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Inventory.h"
#include "Book.h"
#include "User.h"
#include "Purchase.h"
#include "ShoppingCart.h"
#include <exception>
#include <stdexcept>
#include <limits>
using namespace std;
User user;
Inventory inventory;
Purchase purchase;
ShoppingCart cart;
int login();
void displayAdminPage();
void displayCustomerPage();
void displayAdminActivities();
void displayCustomerActivities();
void handleCustomerActivity();
void handleAdminActivity();
int login()
{
int role;
cout<<"\n\n\n********************* Online Bookstore *********************\n\n\n";
cout<<"\n=========================Login To Our Bookstore=================== \n\n";
cout<<"\nWhat is your role? \n"<<" 1-Admin? \t\t\t 2-Customer? \n";
cout<<"\nEnter number 1 if you are admin OR number 2 if you are customer : ";
cin>>role;
while(cin.fail())
{
cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
cout << "Bad entry. PLEASE Enter a NUMBER : ";
cin >> role;
}
return role;
}
void displayAdminPage()
{
cout<<"\n\n\t\t\t--------- Hello Our Admin! ---------\n\n"<<endl;
displayAdminActivities();
handleAdminActivity();
}
void displayCustomerPage()
{
char name[40];
char address[40];
cout<<"\n\n\t\t\t--------- Hello To Our System! ---------\n\n"<<endl;
cout<<"\nPlease enter Your name : \n";
cin.ignore();
cin.getline(name,40);
user.setName(name);
cout<<"\nPlease enter Your address : ";
cin.getline(address,40);
user.setAddress(address);
handleCustomerActivity();
}
void displayAdminActivities()
{
cout<<"\n***************************"<<endl;
cout<<"\nThese are activities which can admin do : "<<endl;
cout<<"1-Display all books in inventory"<<endl;
cout<<"2-Add books in inventory"<<endl;
cout<<"3-Delete books from inventory"<<endl;
cout<<"4-sort books in inventory with price"<<endl;
cout<<"5-Show purchase history of all users"<<endl;
cout<<"6-Back To LOgin"<<endl;
cout<<"7-Exit From System"<<endl;
}
void displayCustomerActivities()
{
cout<<"\n***************************"<<endl;
cout<<"\nThese are activities which you can do : "<<endl;
cout<<"1-Browse books "<<endl;
cout<<"2-Search books by title and author : "<<endl;
cout<<"3-Add books in shopping cart"<<endl;
cout<<"4-Delete books from shopping cart"<<endl;
cout<<"5-Display books in shopping cart"<<endl;
cout<<"6-sort books in inventory with price"<<endl;
cout<<"7-checkout"<<endl;
cout<<"8-Back To LOgin"<<endl;
cout<<"9-Exit From System"<<endl;
}
void searchBook()
{
char title[40];
char author[40];
cout<<"\nPlease choose Book you want to search(enter its title and its author) : "<<endl;
cout<<"\nEnter title of book : ";
cin.ignore();
cin.getline(title,40);
cout<<"\nEnter author of book : ";
cin.getline(author,40);
if(inventory.isExist(title,author) == false)
{
cout<<"This book not found in our inventory \n";
}
}
void handleCustomerActivity()
{
int choice;
int flag=1;
while(flag == 1)
{
displayCustomerActivities();
cout<<"\nchoose number of activity you want to do it :";
cin>>choice;
while(cin.fail())
{
cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
cout << "Bad entry. PLEASE Enter a NUMBER : ";
cin >> choice;
}
switch(choice)
{
case 1:
cout<<"All Books We have : \n";
inventory.displayEntireInventory();
break;
case 2:
searchBook();
break;
case 3:
cart.addBookToCart();
break;
case 4:
cart.removeBookFromUserCart();
break;
case 5:
cart.displayUserCart();
break;
case 6:
inventory.sortBooksByPrice();
break;
case 7:
purchase.checkout(user,cart);
break;
case 8:
{flag=0;
int role=login();
if(role == 1)
displayAdminPage();
else if(role == 2)
displayCustomerPage();
else
cout<<"Wrong Input!"<<endl;
break;}
case 9:
flag=0;
exit(0);
default:
cout<<"You enter a wrong choice "<<endl;
break;
}
}
}
void handleAdminActivity()
{
int choice;
int flag=1;
while(flag == 1)
{
cout<<"\nchoose number of activity you want to do it :";
cin>>choice;
while(cin.fail())
{
cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
cout << "Bad entry. PLEASE Enter a NUMBER : ";
cin >> choice;
}
switch(choice)
{
case 1:
inventory.displayEntireInventory();
break;
case 2:
inventory.addBookToInventory();
break;
case 3:
inventory.deleteBookFromInventory();
break;
case 4:
inventory.sortBooksByPrice();
break;
case 5:
purchase.displayEntirePurchaseHistory();
break;
case 6:
{flag=0;
int role=login();
if(role == 1)
displayAdminPage();
else if(role == 2)
displayCustomerPage();
else
cout<<"Wrong Input!"<<endl;
break;}
case 7:
flag=0;
exit(0);
default:
cout<<"You enter a wrong choice "<<endl;
break;
}
displayAdminActivities();
}
}
int main()
{
int role;
role=login();
if(role == 1)
displayAdminPage();
else if(role == 2)
displayCustomerPage();
else
cout<<"Wrong Input!"<<endl;
return 0;
}