-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickPicks.cpp
More file actions
672 lines (603 loc) · 25.7 KB
/
QuickPicks.cpp
File metadata and controls
672 lines (603 loc) · 25.7 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
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
void headerLines()
{
cout << "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
}
void smallHeaderLines(){
// cout
}
void welcome()
{
cout << endl
<< endl;
headerLines();
cout << "\n\033[1m QuickPicks\033[0m" << endl
<< endl;
headerLines();
cout << endl
<< endl;
cout << "Welcome to QuickPicks !" << endl
<< endl;
}
class Product
{
public:
string pName, pCategory;
int pPrice;
Product(string name, string category, int price)
: pName(name), pCategory(category), pPrice(price) {}
string getName() const { return pName; }
string getCategory() const { return pCategory; }
int getPrice() const { return pPrice; }
};
class userProfile
{
string name, contact, email, address;
string debitAccNo = "Not Available", creditAccNo = "Not Available";
bool isProfileCreated = false;
public:
void createProfile()
{
cout << "\n\033[1mCreate User Profile\033[0m -" << endl;
headerLines();
cout << "\n\033[4mName\033[0m: ";
getline(cin, name);
cout << "\033[4mContact\033[0m: ";
getline(cin, contact);
cout << "\033[4mAddress\033[0m: ";
getline(cin, address);
cout << "\033[4mEmail\033[0m: ";
getline(cin, email);
paymentOpt();
isProfileCreated = true;
cout << "\nProfile Created Successfully!" << endl;
headerLines();
}
void paymentOpt()
{
int paymentOptions;
while (true)
{
cout << "\nPayment Options (1 or 2 or 3):\n1. Add Debit Card.\n2. Add Credit Card.\n3. Add Both.\n--> ";
cin >> paymentOptions;
cin.ignore();
switch (paymentOptions)
{
case 1:
cout << "\033[4mDebit Card no\033[0m: ";
getline(cin, debitAccNo);
return;
case 2:
cout << "\033[4mCredit Card no\033[0m: ";
getline(cin, creditAccNo);
return;
case 3:
cout << "\033[4mDebit Card no\033[0m: ";
getline(cin, debitAccNo);
cout << "\033[4mCredit Card no\033[0m: ";
getline(cin, creditAccNo);
return;
default:
cout << "Invalid Option Entered! Please try again.\n";
break;
}
}
}
void showProfile()
{
if (!isProfileCreated)
{
cout << "\n\033[1mNo profile exists. Please create a profile first.\033[0m\n";
headerLines();
return;
}
cout << "\n\033[1mProfile Information:\033[0m\n";
headerLines();
cout << "\n\033[4mName\033[0m: " << name << "\n";
cout << "\033[4mContact\033[0m: " << contact << "\n";
cout << "\033[4mAddress\033[0m: " << address << "\n";
cout << "\033[4mEmail\033[0m: " << email << "\n";
cout << "\033[4mDebit Card\033[0m: " << debitAccNo << "\n";
cout << "\033[4mCredit Card\033[0m: " << creditAccNo << "\n";
headerLines();
}
void modifyProfile()
{
if (!isProfileCreated)
{
cout << "\n\033[1mNo profile exists. Please create a profile first.\033[0m\n";
return;
}
int choice;
while (true)
{
cout << "\n\033[1mModify Profile:\033[0m\n";
headerLines();
cout << "\n1. Name\n2. Contact\n3. Address\n4. Email\n5. Debit Card Info\n6. Credit Card Info\n7. Exit\n";
cout << "Choose an option to modify: ";
cin >> choice;
cin.ignore();
switch (choice)
{
case 1:
cout << "\033[4mEnter new Name\033[0m: ";
getline(cin, name);
break;
case 2:
cout << "\033[4mEnter new Contact\033[0m: ";
getline(cin, contact);
break;
case 3:
cout << "\033[4mEnter new Address\033[0m: ";
getline(cin, address);
break;
case 4:
cout << "\033[4mEnter new Email\033[0m: ";
getline(cin, email);
break;
case 5:
cout << "\033[4mEnter new Debit Card No\033[0m: ";
getline(cin, debitAccNo);
break;
case 6:
cout << "\033[4mEnter new Credit Card No\033[0m: ";
getline(cin, creditAccNo);
break;
case 7:
cout << "Exiting Modify Menu.\n";
return;
default:
cout << "Invalid Option! Please choose again.\n";
continue;
}
cout << "\n\033[1mUpdated Profile Information:\033[0m\n";
showProfile();
}
}
void manageProfile()
{
int pChoice;
cout << "\n1. Create Profile." << endl
<< "2. Modify Profile." << endl
<< "3. Show Profile." << endl;
cout << "What would you like to do? ";
cin >> pChoice;
cin.ignore();
switch (pChoice)
{
case 1:
createProfile();
break;
case 2:
modifyProfile();
break;
case 3:
showProfile();
break;
default:
cout << "Invalid Option Chosen!" << endl;
manageProfile();
break;
}
}
};
class Cart
{
public:
map<string, int> cartItems; // Store product name and quantity
void addToCart(const string &productName)
{
cartItems[productName]++;
}
void showCart(const vector<Product> &products)
{
cout << "\nItems in your Cart:\n";
float totalPrice = 0;
for (const auto &item : cartItems)
{
for (const auto &product : products)
{
if (product.getName() == item.first)
{
cout << product.getName() << " (x" << item.second << ") - Rs. "
<< product.getPrice() * item.second << endl;
totalPrice += product.getPrice() * item.second;
}
}
}
cout << "\nTotal Price: Rs. " << totalPrice << endl;
}
bool isEmpty()
{
return cartItems.empty();
}
};
class OnlineShoppingSystem
{
public:
vector<Product> products;
userProfile user;
Cart userCart;
void loadProducts()
{
// 1. Electronics.
products.push_back(Product("Smartphone", "Electronics", 15000));
products.push_back(Product("Laptop", "Electronics", 50000));
products.push_back(Product("Smartwatch", "Electronics", 5000));
products.push_back(Product("Headphones", "Electronics", 2000));
products.push_back(Product("TV", "Electronics", 35000));
products.push_back(Product("Refrigerator", "Electronics", 25000));
products.push_back(Product("Washing Machine", "Electronics", 20000));
products.push_back(Product("Microwave Oven", "Electronics", 8000));
products.push_back(Product("Air Conditioner", "Electronics", 40000));
products.push_back(Product("Blender", "Electronics", 3000));
// 2. Fashion.
products.push_back(Product("T-Shirt", "Fashion", 800));
products.push_back(Product("Jeans", "Fashion", 1200));
products.push_back(Product("Sneakers", "Fashion", 2500));
products.push_back(Product("Jacket", "Fashion", 3000));
products.push_back(Product("Sunglasses", "Fashion", 1500));
products.push_back(Product("Cap", "Fashion", 600));
products.push_back(Product("Watch", "Fashion", 3500));
products.push_back(Product("Scarf", "Fashion", 1000));
products.push_back(Product("Belt", "Fashion", 800));
products.push_back(Product("Sweater", "Fashion", 1800));
// 3. Home and Kitchen.
products.push_back(Product("Blender", "Home and Kitchen", 3000));
products.push_back(Product("Toaster", "Home and Kitchen", 1200));
products.push_back(Product("Coffee Maker", "Home and Kitchen", 2500));
products.push_back(Product("Rice Cooker", "Home and Kitchen", 2200));
products.push_back(Product("Microwave Oven", "Home and Kitchen", 8000));
products.push_back(Product("Dishwasher", "Home and Kitchen", 18000));
products.push_back(Product("Electric Kettle", "Home and Kitchen", 1500));
products.push_back(Product("Induction Cooktop", "Home and Kitchen", 3500));
products.push_back(Product("Refrigerator", "Home and Kitchen", 25000));
products.push_back(Product("Air Purifier", "Home and Kitchen", 12000));
// 4. Health and Beauty.
products.push_back(Product("Shampoo", "Health and Beauty", 300));
products.push_back(Product("Conditioner", "Health and Beauty", 350));
products.push_back(Product("Face Cream", "Health and Beauty", 500));
products.push_back(Product("Toothbrush", "Health and Beauty", 150));
products.push_back(Product("Toothpaste", "Health and Beauty", 100));
products.push_back(Product("Hair Oil", "Health and Beauty", 400));
products.push_back(Product("Lip Balm", "Health and Beauty", 150));
products.push_back(Product("Makeup Kit", "Health and Beauty", 1500));
products.push_back(Product("Deodorant", "Health and Beauty", 250));
products.push_back(Product("Sunscreen", "Health and Beauty", 800));
// 5. Sports and Outdoors.
products.push_back(Product("Tennis Racket", "Sports and Outdoors", 2500));
products.push_back(Product("Football", "Sports and Outdoors", 1200));
products.push_back(Product("Yoga Mat", "Sports and Outdoors", 800));
products.push_back(Product("Camping Tent", "Sports and Outdoors", 5000));
products.push_back(Product("Hiking Backpack", "Sports and Outdoors", 3500));
products.push_back(Product("Cycling Helmet", "Sports and Outdoors", 1500));
products.push_back(Product("Fishing Rod", "Sports and Outdoors", 2000));
products.push_back(Product("Baseball Glove", "Sports and Outdoors", 1000));
products.push_back(Product("Water Bottle", "Sports and Outdoors", 300));
products.push_back(Product("Ski Jacket", "Sports and Outdoors", 3500));
// 6. Toys and Baby Products.
products.push_back(Product("Teddy Bear", "Toys and Baby Products", 600));
products.push_back(Product("Building Blocks", "Toys and Baby Products", 1200));
products.push_back(Product("Baby Stroller", "Toys and Baby Products", 5000));
products.push_back(Product("Toy Train Set", "Toys and Baby Products", 1500));
products.push_back(Product("Baby Monitor", "Toys and Baby Products", 3000));
products.push_back(Product("Stuffed Animal", "Toys and Baby Products", 800));
products.push_back(Product("Playmat", "Toys and Baby Products", 1200));
products.push_back(Product("Board Game", "Toys and Baby Products", 1000));
products.push_back(Product("Doll", "Toys and Baby Products", 500));
products.push_back(Product("Baby Feeding Bottle", "Toys and Baby Products", 300));
// 7. Books and Stationary.
products.push_back(Product("Notebook", "Books and Stationery", 150));
products.push_back(Product("Pen Set", "Books and Stationery", 200));
products.push_back(Product("Pencil Box", "Books and Stationery", 250));
products.push_back(Product("Diary", "Books and Stationery", 400));
products.push_back(Product("Textbook", "Books and Stationery", 800));
products.push_back(Product("Colored Pencils", "Books and Stationery", 500));
products.push_back(Product("Eraser", "Books and Stationery", 50));
products.push_back(Product("Glue Stick", "Books and Stationery", 100));
products.push_back(Product("Art Paper", "Books and Stationery", 250));
products.push_back(Product("Planner", "Books and Stationery", 350));
// 8. Groceries and Essentials.
products.push_back(Product("Rice", "Groceries and Essentials", 200));
products.push_back(Product("Sugar", "Groceries and Essentials", 150));
products.push_back(Product("Flour", "Groceries and Essentials", 100));
products.push_back(Product("Salt", "Groceries and Essentials", 50));
products.push_back(Product("Cooking Oil", "Groceries and Essentials", 400));
products.push_back(Product("Tea", "Groceries and Essentials", 250));
products.push_back(Product("Coffee Powder", "Groceries and Essentials", 300));
products.push_back(Product("Pasta", "Groceries and Essentials", 150));
products.push_back(Product("Cereal", "Groceries and Essentials", 500));
products.push_back(Product("Milk", "Groceries and Essentials", 50));
// 9. Automotive and Accessories.
products.push_back(Product("Car Phone Mount", "Automotive and Accessories", 800));
products.push_back(Product("Car Charger", "Automotive and Accessories", 600));
products.push_back(Product("Seat Covers", "Automotive and Accessories", 2000));
products.push_back(Product("Steering Wheel Cover", "Automotive and Accessories", 500));
products.push_back(Product("Car Vacuum Cleaner", "Automotive and Accessories", 2500));
products.push_back(Product("Dashboard Camera", "Automotive and Accessories", 4500));
products.push_back(Product("Car Air Freshener", "Automotive and Accessories", 200));
products.push_back(Product("Jumper Cables", "Automotive and Accessories", 800));
products.push_back(Product("Tire Inflator", "Automotive and Accessories", 1500));
products.push_back(Product("Car Battery", "Automotive and Accessories", 7000));
// 10. Gadgets and Tech Accessories.
products.push_back(Product("Bluetooth Earphones", "Gadgets and Tech Accessories", 1500));
products.push_back(Product("Wireless Mouse", "Gadgets and Tech Accessories", 700));
products.push_back(Product("Laptop Stand", "Gadgets and Tech Accessories", 1200));
products.push_back(Product("Power Bank", "Gadgets and Tech Accessories", 1500));
products.push_back(Product("Phone Case", "Gadgets and Tech Accessories", 600));
products.push_back(Product("Screen Protector", "Gadgets and Tech Accessories", 300));
products.push_back(Product("Keyboard", "Gadgets and Tech Accessories", 1500));
products.push_back(Product("Smartwatch Strap", "Gadgets and Tech Accessories", 800));
products.push_back(Product("Portable Speaker", "Gadgets and Tech Accessories", 2500));
products.push_back(Product("External Hard Drive", "Gadgets and Tech Accessories", 4000));
}
void showCategories()
{
cout << "\nCategories Available:\n";
cout << "1. Electronics\n2. Fashion\n3. Home and Kitchen\n4. Health and Beauty\n5. Sports and Outdoors\n";
cout << "6. Toys and Baby Products\n7. Books and Stationery\n8. Groceries and Essentials\n9. Automotive and Accessories\n";
cout << "10. Gadgets and Tech Accessories\n";
}
void viewProductsByCategory(const string &category)
{
cout << "\nProducts in " << category << ":\n";
bool addMore = true;
while (addMore)
{
int count = 0;
for (const auto &product : products)
{
if (product.pCategory == category)
{
cout << ++count << ". " << product.pName << " - Rs. " << product.pPrice << endl;
}
}
cout << "\nDo you want to add any product to your cart? (y/n): ";
char addChoice;
cin >> addChoice;
if (addChoice == 'y' || addChoice == 'Y')
{
cout << "Enter the product name to add to cart: ";
string productName;
cin.ignore();
getline(cin, productName);
bool found = false;
for (const auto &product : products)
{
if (product.pName == productName && product.pCategory == category)
{
userCart.addToCart(product.pName);
cout << "Product '" << product.pName << "' added to your cart!" << endl;
found = true;
break;
}
}
if (!found)
cout << "Product not found in this category!" << endl;
}
else
{
addMore = false;
}
cout << "\nDo you want to continue viewing products in this category? (y/n): ";
char continueChoice;
cin >> continueChoice;
if (continueChoice != 'y' && continueChoice != 'Y')
addMore = false;
}
}
void searchProduct()
{
cout << "\nDo you want to search by name or category? (Enter 'name' or 'category'): ";
string choice;
cin >> choice;
if (choice == "name")
{
cout << "\nEnter product name: ";
string name;
cin.ignore();
getline(cin, name);
bool found = false;
for (const auto &product : products)
{
if (product.getName() == name)
{
cout << product.getName() << " - Rs. " << product.getPrice() << endl;
cout << "Would you like to add this product to the cart? (y/n): ";
char addChoice;
cin >> addChoice;
if (addChoice == 'y' || addChoice == 'Y')
{
userCart.addToCart(product.getName());
cout << product.getName() << " added to cart.\n";
}
found = true;
break;
}
}
if (!found)
cout << "Product not found!" << endl;
}
else if (choice == "category")
{
showCategories();
cout << "Enter category number: ";
int categoryChoice;
cin >> categoryChoice;
string categories[] = {"Electronics", "Fashion", "Home and Kitchen", "Health and Beauty", "Sports and Outdoors",
"Toys and Baby Products", "Books and Stationery", "Groceries and Essentials", "Automotive and Accessories",
"Gadgets and Tech Accessories"};
if (categoryChoice >= 1 && categoryChoice <= 10)
{
viewProductsByCategory(categories[categoryChoice - 1]);
cout << "Would you like to add any product to your cart? (y/n): ";
char addChoice;
cin >> addChoice;
if (addChoice == 'y' || addChoice == 'Y')
{
cout << "Enter product name to add to cart: ";
cin.ignore();
string name;
getline(cin, name);
userCart.addToCart(name);
cout << name << " added to cart.\n";
}
}
else
{
cout << "Invalid category!" << endl;
}
}
}
void checkout()
{
if (userCart.isEmpty())
{
cout << "\nYour cart is empty. Add items to your cart before checkout.\n";
return;
}
userCart.showCart(products);
cout << "\nDo you want to proceed to checkout? (y/n): ";
char proceed;
cin >> proceed;
if (proceed == 'y' || proceed == 'Y')
{
cout << "\nThank you for shopping with us! Your order will be processed shortly.\n";
}
else
{
cout << "\nCheckout canceled.\n";
}
}
void displayMenu()
{
int choice;
while (true)
{
cout << "\n--> What would you like to do?\n";
cout << "1. Profile\n2. Cart\n3. Orders\n4. View Products\n5. Checkout\n6. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
cout << endl;
switch (choice)
{
case 1:
user.manageProfile();
break;
case 2:
userCart.showCart(products);
break;
case 3:
cout << "Orders functionality coming soon!" << endl;
break;
case 4:
// Keep viewing products until the user wants to exit
while (true)
{
cout << "\nDo you want to search by name or category? (Enter 'name' or 'category'), or 'exit' to go back: ";
string searchChoice;
cin >> searchChoice;
if (searchChoice == "name")
{
cout << "\nEnter product name: ";
string name;
cin.ignore();
getline(cin, name);
bool found = false;
for (const auto &product : products)
{
if (product.pName == name)
{
cout << product.pName << " - Rs. " << product.pPrice << endl;
// Add to cart option
cout << "Do you want to add this product to your cart? (y/n): ";
char addChoice;
cin >> addChoice;
if (addChoice == 'y' || addChoice == 'Y')
{
userCart.addToCart(product.pName);
cout << "Product added to your cart!" << endl;
}
found = true;
break;
}
}
if (!found)
cout << "Product not found!" << endl;
}
else if (searchChoice == "category")
{
showCategories();
cout << "Enter category number: ";
int categoryChoice;
cin >> categoryChoice;
string categories[] = {"Electronics", "Fashion", "Home and Kitchen", "Health and Beauty", "Sports and Outdoors",
"Toys and Baby Products", "Books and Stationery", "Groceries and Essentials", "Automotive and Accessories",
"Gadgets and Tech Accessories"};
if (categoryChoice >= 1 && categoryChoice <= 10)
{
viewProductsByCategory(categories[categoryChoice - 1]);
// After viewing the category, prompt for adding to cart
cout << "\nDo you want to add a product to your cart? (y/n): ";
char addChoice;
cin >> addChoice;
if (addChoice == 'y' || addChoice == 'Y')
{
string productName;
cout << "Enter the product name to add to cart: ";
cin.ignore();
getline(cin, productName);
bool added = false;
for (const auto &product : products)
{
if (product.pName == productName && product.pCategory == categories[categoryChoice - 1])
{
userCart.addToCart(product.pName);
cout << "Product added to your cart!" << endl;
added = true;
break;
}
}
if (!added)
cout << "Product not found in the selected category!" << endl;
}
}
else
{
cout << "Invalid category!" << endl;
}
}
else if (searchChoice == "exit") // Option to exit the search
{
break; // Exit product viewing loop and return to the main menu
}
else
{
cout << "Invalid choice! Please try again." << endl;
}
}
break;
case 5:
checkout();
break;
case 6:
cout << "Exiting. Thank you!" << endl;
return;
default:
cout << "Invalid choice! Please try again." << endl;
}
}
}
};
int main()
{
welcome();
OnlineShoppingSystem system;
system.loadProducts();
system.displayMenu();
return 0;
}