-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopping.cpp
399 lines (367 loc) · 10.3 KB
/
shopping.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
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#include <iostream>
#include <string>
#include <sstream>
#include <bits/stdc++.h>
#include <windows.h>
#include "queue1.h"
#include "animation.h"
#include "stackme.h"
using namespace std;
int search(int);
int display();
string check(int); // for checking quantity
////////////////////////////////////////////////////////////////////
struct node
{
int ID;
string proName;
double prePrice;
int quantity;
struct node *next;
};
struct node *head = NULL;
////////////////////////////////////////////////////////////////////
void beg()
{
system("cls");
int id, quant; // quant for quantity
string name;
double pre; // pre for price
struct node *t = new node;
struct node *p = head;
cout << "\t\t\tEnter product ID:-";
cin >> id;
t->ID = id;
cout << "\t\t\tEnter product Name:-";
cin >> name;
t->proName = name;
cout << "\t\t\tEnter product price:-";
cin >> pre;
t->prePrice = pre;
cout << "\t\t\tEnter product quantity:-";
cin >> quant;
t->quantity = quant;
if (head == NULL)
{
t->next = head;
head = t;
}
else
{
while (p->next != NULL)
{
p = p->next;
}
p->next = t;
t->next = NULL;
}
system("cls");
cout << "\n\n\t\t\t\tThis product is Inserted!\n\n\n";
}
///////////////////////////////////////////////////////////////////////////////////////////
int search(int id) // for search item in list
{
int count = 1;
struct node *p = head;
while (p != NULL)
{
if (p->ID == id)
break;
else
count++;
p = p->next;
}
return count;
}
///////////////////////////////////////////////////////////////////////
int customhash(int x, int mod)
{
return x % mod;
}
////////////////////////////////////////////////////////////////////////
void delPro()
{
system("cls");
display();
int id;
struct node *cur = head;
struct node *pre = head;
cout << "\n\nEnter ID to delete that product:\n\n";
cin >> id;
if (head == NULL)
{
system("cls");
cout << "List is empty" << endl;
}
int pos = 0;
int count = display(); // for load no of nodes
pos = search(id); // for check whether desire node is exist or not
if (pos <= count)
{
while (cur->ID != id)
{ // for delete middle area products
pre = cur;
cur = cur->next;
}
pre->next = cur->next;
system("cls");
cout << "\n<<item is deleted>>\n";
}
else
{
cout << "\n<<<Not found>>\n\n";
}
}
//////////////////////////////////////////////////////////////////////////////////
void modify()
{
int id;
double pre; // pre for price
string pName;
int nid;
int nq; // pName for new name
if (head == NULL)
{
system("cls");
cout << "List is empty" << endl;
}
else
{
display();
cout << "\n\nEnter ID to modify product Name and its price:\n";
cin >> id;
struct node *cur = head;
int pos = 0;
int count = display(); // for load no of nodes
pos = search(id);
// for check whether desire node is exist or not
if (pos <= count)
{
while (cur->ID != id)
{
cur = cur->next;
}
cout << "\nOld ID : " << cur->ID << endl;
cout << "\nOld Name : " << cur->proName << endl;
cout << "\nOld Price : " << cur->prePrice << endl;
cout << "\nOld Quantity : " << cur->quantity << endl;
cout << endl
<< endl;
cout << "Enter new ID:";
cin >> nid;
cur->ID = nid;
cout << "Enter new Name:";
cin >> pName;
cur->proName = pName;
cout << "Enter new Price:";
cin >> pre;
cur->prePrice = pre;
cout << "Enter new Quantity:";
cin >> nq;
cur->quantity = nq;
}
else
{
cout << id << " is <<<Not found>>\n\n";
}
}
}
//////////////////////////////////////////////////////////////////////////////////////
int display()
{
system("cls");
int c = 0; // c for count products
struct node *p = head;
cout << "Existing products are:\n";
cout << "ID\t\tProduct Name\t\t\tPrice\t\tQuantity\n";
cout << "=================================================================|\n";
while (p != NULL)
{
cout << p->ID << "\t\t" << p->proName << "\t\t\t" << p->prePrice << "\t\t\t" << check(p->quantity) << "\n"; // call check func and pass quantity
p = p->next;
c = c + 1;
}
cout << "\nTotal products in our store are: " << c << "\n\n\n";
return c;
}
////////////////////////////////////////////////////////////////////////////////////////
string check(int quant)
{ // check function
int a = quant;
stringstream ss;
ss << a;
string quantity = ss.str();
if (quant <= 0)
return "out of stock!";
else
return quantity;
}
///////////////////////////////////////////////////////////////////////
void buy()
{
system("cls");
display();
string products[20];
// for display sold items
int pay = 0, no, c = 0, price, id, i = 1;
if (head == NULL)
{
cout << "\n<<<<There are no items to buy>>>>\n\n";
}
else
{
cout << "How many items do you want to buy?\n";
cin >> no;
int count = display(); // for store no of nodes in c
while (i <= no)
{
struct node *cur = head;
int quant, cho; a: // quant for quantity and cho for choice
cout << "Enter the ID of the item that you want to buy: ";
int id, pos = 0;
cin >> id;
if (id == -1)
{
system("cls");
return;
}
pos = search(id);
if (pos <= count)
{ // item is available in store
while (cur->ID != id)
{
cur = cur->next;
}
cout << "How many quantities do you want:";
cin >> quant;
if (cur->quantity < quant)
{
cout << "\n\n\t\t\t----The Quantity You Entered is not available---" << endl;
cout << "\n\t\t\t-----(Press -1 for Back to Main Menu)------" << endl;
goto a;
}
products[c] = cur->proName; // this will contain the items buy names in the array;
c++;
pay = pay + (cur->prePrice * quant); // calculate Bill
cur->quantity = cur->quantity - quant; // change quantity
i++;
}
else
{
cout << "\n<<<<<<<<<This item is not available in our store at this time>>>>\n\n";
}
}
string customer;
cout << "\n\t\t Enter Your Name :";
cin >> customer;
enqueue(customer);
system("cls");
cout << "\n\n\n\n\t\t\tYou have bought : ";
for (int i = 0; i < no; i++)
{ // show that item you have bought
cout << products[i] << ",";
}
price = pay * (0.90); // with 10% discount
cout << "\n\nOriginal price : " << pay;
cout << "\n with 10% discount: " << price << "\nThank you! for shopping\n\n";
}
}
///////////////////////////////////////////////////////////////////////////////////////
void administator()
{
system("cls");
int ch;
do
{
// choice for below message
cout << "\t\t============================================" << endl;
cout << "\t\t| Administrator Portal |" << endl;
cout << "\t\t============================================" << endl;
cout << "\t\t Enter 1 for ADD a new product " << endl;
cout << "\t\t Enter 2 to display all products " << endl;
cout << "\t\t Enter 3 for MODIFY Existing product" << endl;
cout << "\t\t Enter 4 for Delete a particular product item" << endl;
cout << "\t\t Enter 5 for Customers List " << endl;
cout << "\t\t Enter 6 for Dequeue customer" << endl;
cout << "\t\t Enter 7 for Generate customhash" << endl;
cout << "\t\t Enter 0 for Main Menu" << endl;
cout << "\nEnter Your choice >>>";
cin >> ch;
switch (ch)
{
case 1:
beg();
break;
case 2:
system("cls");
display();
break;
case 3:
modify();
system("cls");
break;
case 4:
delPro();
cout << "\n-------Product is Deleted-------\n";
break;
case 5:
system("cls");
cout << "|============CUSTOMERS NAMES LIST==============|\n";
displayQueue();
break;
case 6:
system("cls");
cout << "|============CUSTOMERS NAMES LIST==============|\n";
dequeue();
displayQueue();
break;
case 7:
int x, n;
cout << "Enter element to generate customhash = ";
cin >> x;
cout << "Of the total list number : ";
cin >> n;
cout << "Hash of " << x << " is = " << customhash(x, n);
break;
default:
system("cls");
}
} while (ch != 0);
}
// Main function
int main()
{
for (int i = 0; i <= 51; i++)
{
push(i);
}
int ch;
while (ch != 3)
{
// choice for below message
cout << "\n\t\t|--------<Main Menu>-----------|";
cout << "\n\n";
cout << "\t\t 1) Administrator of Market\n";
cout << "\t\t 2) Customer \n";
cout << "\t\t 3) Exit \n";
cout << "\nEnter Your choice >>>";
cin >> ch;
switch (ch)
{
case 1:
administator();
break;
case 2:
cout << endl
<< endl;
bpop();
system("pause");
buy();
break;
case 3:
cout << "\n\n\t\t\t\t\tThank You\t\t\t\t";
break;
}
}
return 0;
}