-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.cpp
More file actions
1275 lines (1093 loc) · 42.6 KB
/
Customer.cpp
File metadata and controls
1275 lines (1093 loc) · 42.6 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
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include"Customer.h"
using namespace std;
// Constants for limits
const int MAX_PRODUCTS = 100;
const int MAX_CUSTOMERS = 100;
const int MAX_CART_SIZE = 500;
const int MAX_WISHLIST_ITEMS = 50;
const int MAX_ORDER_HISTORY = 100;
const int MAX_SUPPORT_REQUESTS = 200;
// Global arrays
char productNames[MAX_PRODUCTS][50];
int productIDs[MAX_PRODUCTS];
double ProductPrices[MAX_PRODUCTS];
int ProductStockQuantities[MAX_PRODUCTS];
char ProductCategories[MAX_PRODUCTS][50];
int ProductSoldQuantities[MAX_PRODUCTS] = {0};
char customerUsernames[MAX_CUSTOMERS][50];
char customerPasswords[MAX_CUSTOMERS][50];
int cartProductIDs[MAX_CUSTOMERS][MAX_CART_SIZE];
int cartQuantities[MAX_CUSTOMERS][MAX_CART_SIZE];
double cartTotals[MAX_CUSTOMERS] = {0.0};
int cartSizes[MAX_CUSTOMERS] = {0};
int catalogsize = 0;
int customerCount = 0;
int wishlistProductIDs[MAX_CUSTOMERS][MAX_WISHLIST_ITEMS];
int wishlistSizes[MAX_CUSTOMERS] = {0};
char orderHistoryProductNames[MAX_CUSTOMERS][MAX_ORDER_HISTORY][50];
int orderHistoryProductIDs[MAX_CUSTOMERS][MAX_ORDER_HISTORY];
double orderHistoryPrices[MAX_CUSTOMERS][MAX_ORDER_HISTORY];
char orderHistoryDates[MAX_CUSTOMERS][MAX_ORDER_HISTORY][20];
int orderHistoryCount[MAX_CUSTOMERS] = {0};
char SupportRequests[MAX_SUPPORT_REQUESTS][200];
int SupportRequestCount = 0;
void customerloginmenu()
{
loadOrderHistory(); // Load order history
LoadSupportRequests(); // Load support requests
loadCatalog(); // Load product catalog from file
loadCustomers(); // Load customers from file
loadWishlist();
char c;
while (true)
{
// Welcome message with alignment
cout << "\n\t\t\t====================================" << endl;
cout << "\t\t\t Welcome to SecureShop" << endl;
cout << "\t\t\t====================================" << endl;
// Menu options with better alignment
cout << "\n\t1. Login" << endl;
cout << "\t2. Register" << endl;
cout << "\t3. Forgot Password" << endl;
cout << "\t4. Exit" << endl;
// Input prompt
cout << "\n\t------------------------------------" << endl;
cout << "\t\tEnter your choice: ";
cin >> c;
// Switch case for handling different choices
switch (c)
{
case '1':
cout << "\nRedirecting to Login...\n";
customerlogin();
break;
case '2':
cout << "\nRedirecting to Registration...\n";
registration();
break;
case '3':
cout << "\nRedirecting to Forgot Password...\n";
forgot();
break;
case '4':
cout << "\nSaving catalog and customer data...\n";
save_Catalog();
saveCustomers();
saveWishlist();
cout << "\nThank you for using SecureShop! Have a great day!\n";
exit(0);
break;
default:
cout << "\nInvalid choice. Please try again.\n";
}
}
}
// User Authentication8
void customerlogin()
{
char username[50], password[50];
// Prompt for username and password
cout << "\n====================================" << endl;
cout << " Login to SecureShop " << endl;
cout << "====================================" << endl;
cout << "\n\tUsername: ";
cin >> username;
cout << "\tPassword: ";
cin >> password;
// Check credentials and provide feedback
for (int i = 0; i < customerCount; i++)
{
if (strcmp(customerUsernames[i], username) == 0 && strcmp(customerPasswords[i], password) == 0)
{
cout << "\n====================================" << endl;
cout << " Login Successful! " << endl;
cout << "====================================" << endl;
customerMenu(username);
return;
}
}
// Invalid login message
cout << "\n====================================" << endl;
cout << " Invalid username or password." << endl;
cout << "====================================" << endl;
}
void registration()
{
if (customerCount >= MAX_CUSTOMERS) {
cout << "\n====================================" << endl;
cout << " Registration Limit Reached! " << endl;
cout << "====================================" << endl;
cout << "Cannot register more users.\n";
return;
}
char username[50], password[50];
// Prompt for username and password
cout << "\n====================================" << endl;
cout << " Register New User " << endl;
cout << "====================================" << endl;
cout << "\n\tEnter a username: ";
cin >> username;
cout << "\tEnter a password: ";
cin >> password;
// Check if username already exists
for (int i = 0; i < customerCount; i++)
{
if (strcmp(customerUsernames[i], username) == 0) {
cout << "\n====================================" << endl;
cout << " Username already exists. Try a different one." << endl;
cout << "====================================" << endl;
return;
}
}
// Register new user
strcpy(customerUsernames[customerCount], username);
strcpy(customerPasswords[customerCount], password);
customerCount++;
// Registration success message
cout << "\n====================================" << endl;
cout << " Registration Successful! " << endl;
cout << "====================================" << endl;
}
void forgot()
{
char username[50];
// Prompt for username with clear formatting
cout << "\n====================================" << endl;
cout << " Forgot Password " << endl;
cout << "====================================" << endl;
cout << "\n\tEnter your username: ";
cin >> username;
// Search for the username and display password if found
for (int i = 0; i < customerCount; i++)
{
if (strcmp(customerUsernames[i], username) == 0) {
cout << "\n====================================" << endl;
cout << " Your password is: " << customerPasswords[i] << endl;
cout << "====================================" << endl;
return;
}
}
// Error message for username not found
cout << "\n====================================" << endl;
cout << " Username not found. Please try again." << endl;
cout << "====================================" << endl;
}
// Customer Panel
void customerMenu(const char* username)
{
// Find the logged-in customer index
int customerIndex = -1;
for (int i = 0; i < customerCount; i++) {
if (strcmp(customerUsernames[i], username) == 0) {
customerIndex = i;
break;
}
}
// Check if customer exists
if (customerIndex == -1)
{
cout << "\n====================================" << endl;
cout << " Error: Customer Not Found " << endl;
cout << "====================================" << endl;
return;
}
// Customer menu loop
while (true)
{
char choice;
cout << "\n====================================" << endl;
cout << " Customer Panel " << endl;
cout << "====================================" << endl;
// Display menu options with new features
cout << "\t1. View All Products" << endl;
cout << "\t2. Search Products" << endl;
cout << "\t3. Manage Cart" << endl;
cout << "\t4. Wishlist" << endl;
cout << "\t5. Order History" << endl;
cout << "\t6. Product Feedback" << endl;
cout << "\t7. Support Request" << endl;
cout << "\t8. Logout" << endl;
cout << "\n\tEnter your choice: ";
cin >> choice;
// Handle menu choices
switch (choice) {
case '1':
cout << "\nDisplaying all products...\n";
displayProducts();
break;
case '2':
cout << "\nInitiating product search...\n";
advancedSearch();
break;
case '3':
cout << "\nManaging your cart...\n";
manageCart(customerIndex);
break;
case '4': {
int wishlistChoice;
cout << "\n1. Add to Wishlist\n2. View Wishlist\n3. Remove from Wishlist\n";
cin >> wishlistChoice;
switch(wishlistChoice) {
case 1: addToWishlist(customerIndex); break;
case 2: viewWishlist(customerIndex); break;
case 3: removeFromWishlist(customerIndex); break;
}
break;
}
case '5':
viewOrderHistory(customerIndex);
break;
case '6':
submitFeedback(customerIndex);
break;
case '7':
submitSupportRequest(customerIndex);
break;
case '8':
cout << "\nLogging out...\n";
return; // Logout
default:
cout << "\n====================================" << endl;
cout << " Invalid choice. Please try again." << endl;
cout << "====================================" << endl;
}
}
}
void addItemToCart(int customerIndex)
{
int productID, quantity;
// Prompt for product ID to add to the cart
cout << "\n====================================" << endl;
cout << " Add Item to Cart " << endl;
cout << "====================================" << endl;
cout << "\n\tEnter the Product ID to add to the cart: ";
cin >> productID;
// Search for the product in the catalog
for (int i = 0; i < catalogsize; i++)
{
if (productIDs[i] == productID) {
// Check if the product is out of stock
if (ProductStockQuantities[i] == 0)
{
cout << "\n====================================" << endl;
cout << " This product is out of stock. " << endl;
cout << "====================================" << endl;
return;
}
// Prompt for quantity to add to the cart
cout << "\n\tEnter quantity: ";
cin >> quantity;
// Check if the requested quantity exceeds available stock
if (quantity > ProductStockQuantities[i])
{
cout << "\n====================================" << endl;
cout << " Quantity exceeds available stock. Try again." << endl;
cout << "====================================" << endl;
return;
}
// Check if the item is already in the cart
for (int j = 0; j < cartSizes[customerIndex]; j++)
{
if (cartProductIDs[customerIndex][j] == productID) {
cartQuantities[customerIndex][j] += quantity;
ProductStockQuantities[i] -= quantity;
calculateCartTotal(customerIndex);
cout << "\n====================================" << endl;
cout << " Item updated in cart successfully." << endl;
cout << "====================================" << endl;
return;
}
}
// Add new item to cart
cartProductIDs[customerIndex][cartSizes[customerIndex]] = productID;
cartQuantities[customerIndex][cartSizes[customerIndex]] = quantity;
cartSizes[customerIndex]++;
ProductStockQuantities[i] -= quantity;
calculateCartTotal(customerIndex);
// Confirmation message
cout << "\n====================================" << endl;
cout << " Item added to cart successfully." << endl;
cout << "====================================" << endl;
return;
}
}
// If product not found
cout << "\n====================================" << endl;
cout << " Product not found. Try again." << endl;
cout << "====================================" << endl;
}
void removeItemFromCart(int customerIndex)
{
int productID;
// Prompt to enter product ID to remove from the cart
cout << "\n====================================" << endl;
cout << " Remove Item from Cart " << endl;
cout << "====================================" << endl;
cout << "\n\tEnter the Product ID to remove from the cart: ";
cin >> productID;
// Search for the product in the customer's cart
for (int i = 0; i < cartSizes[customerIndex]; i++)
{
if (cartProductIDs[customerIndex][i] == productID)
{
// Restore stock to the catalog
for (int j = 0; j < catalogsize; j++)
{
if (productIDs[j] == productID)
{
ProductStockQuantities[j] += cartQuantities[customerIndex][i];
}
}
// Remove item from the cart (shift items left)
for (int j = i; j < cartSizes[customerIndex] - 1; j++)
{
cartProductIDs[customerIndex][j] = cartProductIDs[customerIndex][j + 1];
cartQuantities[customerIndex][j] = cartQuantities[customerIndex][j + 1];
}
// Decrease the cart size
cartSizes[customerIndex]--;
calculateCartTotal(customerIndex);
// Confirmation message
cout << "\n====================================" << endl;
cout << " Item removed from cart. " << endl;
cout << "====================================" << endl;
return;
}
}
// If product not found in the cart
cout << "\n====================================" << endl;
cout << " Item not found in cart. " << endl;
cout << "====================================" << endl;
}
void calculateCartTotal(int customerIndex)
{
cartTotals[customerIndex] = 0.0;
for (int i = 0; i < cartSizes[customerIndex]; i++)
{
int productID = cartProductIDs[customerIndex][i];
for (int j = 0; j < catalogsize; j++)
{
if (productIDs[j] == productID)
{
cartTotals[customerIndex] += ProductPrices[j] * cartQuantities[customerIndex][i];
break;
}
}
}
}
void viewCart(int customerIndex)
{
// Check if cart is empty
if (cartSizes[customerIndex] == 0)
{
cout << "\n====================================" << endl;
cout << " Your cart is empty. " << endl;
cout << "====================================" << endl;
return;
}
// Display cart details
cout << "\n====================================" << endl;
cout << " Your Cart " << endl;
cout << "====================================" << endl;
cout << "ID Name Price Quantity" << endl;
cout << "-----------------------------------------------" << endl;
// Loop through the cart and display product details
for (int i = 0; i < cartSizes[customerIndex]; i++)
{
int productID = cartProductIDs[customerIndex][i];
for (int j = 0; j < catalogsize; j++)
{
if (productIDs[j] == productID)
{
// Display each product in the cart
cout << productID << " "
<< productNames[j] << " "
<< "$" << ProductPrices[j] << " "
<< cartQuantities[customerIndex][i] << endl;
break;
}
}
}
// Display the cart total
cout << "-----------------------------------------------" << endl;
cout << "\nTotal Amount: $" << cartTotals[customerIndex] << endl;
cout << "====================================" << endl;
}
void applyDiscount(int customerIndex)
{
// Check if cart is empty
if (cartSizes[customerIndex] == 0)
{
cout << "\n====================================" << endl;
cout << " Your cart is empty. " << endl;
cout << " No discounts available. " << endl;
cout << "====================================" << endl;
return;
}
double discount = 0.0;
// Display available promotions
cout << "\n====================================" << endl;
cout << " Available Promotions " << endl;
cout << "====================================" << endl;
cout << "1. 10% off for orders above $100" << endl;
cout << "2. $15 off for orders above $200" << endl;
cout << "Enter choice (or 0 to skip): ";
char choice;
cin >> choice;
// Apply selected discount
switch (choice)
{
case '1':
if (cartTotals[customerIndex] > 100)
{
discount = cartTotals[customerIndex] * 0.10;
cartTotals[customerIndex] -= discount;
cout << "Discount applied: -$" << discount << endl;
} else
{
cout << "Your cart total does not qualify for this discount.\n";
}
break;
case '2':
if (cartTotals[customerIndex] > 200)
{
discount = 15.0;
cartTotals[customerIndex] -= discount;
cout << "Discount applied: -$" << discount << endl;
} else
{
cout << "Your cart total does not qualify for this discount.\n";
}
break;
case '0':
cout << "No discount applied.\n";
break;
default:
cout << "Invalid choice. Please try again.\n";
}
// Show the updated total after discount
cout << "\n====================================" << endl;
cout << " Updated Cart Total: $" << cartTotals[customerIndex] << endl;
cout << "====================================" << endl;
}
void manageCart(int customerIndex)
{
while (true) {
// Cart Management Header
cout << "\n====================================" << endl;
cout << " --- Cart Management --- " << endl;
cout << "====================================" << endl;
// Cart Management Options
cout << "1. Add Item to Cart\n";
cout << "2. Remove Item from Cart\n";
cout << "3. View Cart\n";
cout << "4. Apply Discount\n";
cout << "5. Checkout\n";
cout << "6. Back to Main Menu\n";
cout << "------------------------------------" << endl;
cout << "Enter your choice: ";
char choice;
cin >> choice;
// Process user choice
switch (choice)
{
case '1':
addItemToCart(customerIndex);
break;
case '2':
removeItemFromCart(customerIndex);
break;
case '3':
viewCart(customerIndex);
break;
case '4':
applyDiscount(customerIndex);
break;
case '5':
{
// Checkout
cout << "\n====================================" << endl;
cout << " Checking out... Final total: $" << cartTotals[customerIndex] << endl;
cout << "====================================" << endl;
// Record order history before clearing the cart
recordOrderHistory(customerIndex);
// Reset cart after checkout
cartSizes[customerIndex] = 0; // Clear the cart
cartTotals[customerIndex] = 0.0;
return;
}
case '6':
return; // Go back to main menu
default:
cout << "\nInvalid choice. Please try again.\n";
}
}
}
void displayProducts()
{
// Check if catalog is empty
if (catalogsize == 0) {
cout << "\n====================================" << endl;
cout << " No products available in the catalog." << endl;
cout << "====================================\n";
return;
}
// Display product header
cout << "\n====================================" << endl;
cout << " Available Products " << endl;
cout << "====================================" << endl;
// Display table headers with spacing
cout << "ID Name Price Stock Category" << endl;
cout << "------------------------------------------------------------" << endl;
// Display all products in catalog
for (int i = 0; i < catalogsize; i++)
{
cout << productIDs[i] << " "
<< left << setw(20) << productNames[i] << " " << right << setw(8) << fixed << setprecision(2) << ProductPrices[i] << " "
<< right << setw(5) << ProductStockQuantities[i] << " " << left << setw(15) << ProductCategories[i] << endl;
}
cout << "------------------------------------------------------------\n";
}
void advancedSearch()
{
// Dynamically allocate memory for category
char* category = new char[50];
category[0] = '\0'; // Initialize to an empty string
double minPrice = 0.0, maxPrice = 1e9;
int availabilityOption = -1;
cout << "\n====================================" << endl;
cout << " Advanced Product Search " << endl;
cout << "====================================" << endl;
// Get search criteria
cout << "Enter category (leave blank for any): ";
cin.ignore();
cin.getline(category, 50);
cout << "Enter minimum price (default 0): ";
cin >> minPrice;
cout << "Enter maximum price (leave blank or 0 for no limit): ";
cin >> maxPrice;
// Availability options
cout << "\nAvailability options:\n";
cout << "1. In Stock\n2. Out of Stock\n3. Any\n";
cout << "Enter choice: ";
cin >> availabilityOption;
cout << "\n====================================" << endl;
cout << " Search Results " << endl;
cout << "====================================" << endl;
cout << "ID Name Price Stock Category" << endl;
cout << "------------------------------------------------------------\n";
bool found = false;
for (int i = 0; i < catalogsize; i++)
{
bool categoryMatch = (strlen(category) == 0 || strcmp(ProductCategories[i], category) == 0);
bool priceMatch = (ProductPrices[i] >= minPrice && ProductPrices[i] <= maxPrice);
bool stockMatch = true;
// Check stock availability
if (availabilityOption == 1)
stockMatch = (ProductStockQuantities[i] > 0);
else if (availabilityOption == 2)
stockMatch = (ProductStockQuantities[i] == 0);
// If all conditions match, display the product
if (categoryMatch && priceMatch && stockMatch)
{
cout << productIDs[i] << " "
<< left << setw(20) << productNames[i] << " " << right << setw(8) << fixed << setprecision(2) << ProductPrices[i] << " "
<< right << setw(5) << ProductStockQuantities[i] << " " << left << setw(15) << ProductCategories[i] << endl;
found = true;
}
}
if (!found)
{
cout << "No products match the search criteria.\n";
}
cout << "------------------------------------------------------------\n";
delete[] category;
}
// Persistent Storage
void loadCatalog()
{
ifstream file("catalog.txt");
if (file.is_open()) {
while (catalogsize < MAX_PRODUCTS &&
file >> productIDs[catalogsize] >> ProductPrices[catalogsize] >> ProductStockQuantities[catalogsize] >> ProductSoldQuantities[catalogsize])
{
file.ignore();
file.getline(productNames[catalogsize], 50);
file.getline(ProductCategories[catalogsize], 50);
catalogsize++;
}
file.close();
}
}
void submitSupportRequest(int customerIndex)
{
// Check if support request limit is reached
if (SupportRequestCount >= MAX_SUPPORT_REQUESTS)
{
cout << "\n====================================" << endl;
cout << " Support Request Limit Reached " << endl;
cout << "====================================" << endl;
return;
}
// Declare support request message
char supportMessage[200];
// Prompt for support request
cout << "\n====================================" << endl;
cout << " Submit Support Request " << endl;
cout << "====================================" << endl;
cout << "\nPlease describe your support issue (max 200 characters): ";
cin.ignore(); // Clear any previous input buffer
cin.getline(supportMessage, 200);
// If user didn't enter anything, cancel
if (strlen(supportMessage) == 0)
{
cout << "\nSupport request canceled.\n";
return;
}
// Create a detailed support request with customer username
char fullSupportRequest[250];
snprintf(fullSupportRequest, sizeof(fullSupportRequest),
"Customer: %s - Request: %s",
customerUsernames[customerIndex], supportMessage);
// Add support request to global array
strcpy(SupportRequests[SupportRequestCount], fullSupportRequest);
SupportRequestCount++;
// Optionally save support requests immediately
SaveSupportRequests();
// Confirmation message
cout << "\n====================================" << endl;
cout << " Support Request Submitted! " << endl;
cout << "====================================" << endl;
}
void save_Catalog()
{
ofstream file("catalog.txt");
if (!file.is_open()) {
cout << "Error: Unable to open catalog.txt for saving.\n";
return;
}
for (int i = 0; i < catalogsize; i++) {
file << productIDs[i] << ' ' << ProductPrices[i] << ' ' << ProductStockQuantities[i] << ' ' << ProductSoldQuantities[i] << '\n'
<< productNames[i] << '\n' << ProductCategories[i] << '\n';
}
saveOrderHistory(); // Save order history
SaveSupportRequests();
saveWishlist();
//saveSupport;
file.close();
}
void loadCustomers()
{
ifstream file("customers.txt");
if (file.is_open())
{
while (customerCount < MAX_CUSTOMERS &&
file >> customerUsernames[customerCount] >> customerPasswords[customerCount])
{
customerCount++;
}
file.close();
}
}
void saveCustomers()
{
ofstream file("customers.txt");
for (int i = 0; i < customerCount; i++)
{
file << customerUsernames[i] << ' ' << customerPasswords[i] << '\n';
}
file.close();
}
void addToWishlist(int customerIndex) {
int productID;
// Check if wishlist is full
if (wishlistSizes[customerIndex] >= MAX_WISHLIST_ITEMS) {
cout << "\n====================================" << endl;
cout << " Wishlist is full. Remove an item first." << endl;
cout << "====================================" << endl;
return;
}
// Prompt for product ID
cout << "\n====================================" << endl;
cout << " Add to Wishlist " << endl;
cout << "====================================" << endl;
cout << "\n\tEnter Product ID to add to wishlist: ";
cin >> productID;
// Check if product exists in catalog
for (int i = 0; i < catalogsize; i++) {
if (productIDs[i] == productID) {
// Check if already in wishlist
for (int j = 0; j < wishlistSizes[customerIndex]; j++) {
if (wishlistProductIDs[customerIndex][j] == productID) {
cout << "\n====================================" << endl;
cout << " Product already in wishlist. " << endl;
cout << "====================================" << endl;
return;
}
}
// Add to wishlist
wishlistProductIDs[customerIndex][wishlistSizes[customerIndex]] = productID;
wishlistSizes[customerIndex]++;
// Save wishlist using standard method
saveWishlist();
cout << "\n====================================" << endl;
cout << " Product added to wishlist. " << endl;
cout << " Wishlist saved. " << endl;
cout << "====================================" << endl;
return;
}
}
// Product not found
cout << "\n====================================" << endl;
cout << " Product not found in catalog. " << endl;
cout << "====================================" << endl;
}
// Implement View Wishlist
void viewWishlist(int customerIndex)
{
// Check if wishlist is empty
if (wishlistSizes[customerIndex] == 0)
{
cout << "\n====================================" << endl;
cout << " Your Wishlist is Empty " << endl;
cout << "====================================" << endl;
return;
}
// Display wishlist header
cout << "\n====================================" << endl;
cout << " Your Wishlist " << endl;
cout << "====================================" << endl;
cout << "ID Name Price Stock Category" << endl;
cout << "------------------------------------------------------------" << endl;
// Iterate through wishlist and display details
for (int i = 0; i < wishlistSizes[customerIndex]; i++)
{
int productID = wishlistProductIDs[customerIndex][i];
for (int j = 0; j < catalogsize; j++)
{
if (productIDs[j] == productID)
{
cout << productIDs[j] << " " << left << setw(20) << productNames[j] << " " << right << setw(8) << fixed << setprecision(2) << ProductPrices[j] << " "
<< right << setw(5) << ProductStockQuantities[j] << " " << left << setw(15) << ProductCategories[j] << endl;
break;
}
}
}
cout << "------------------------------------------------------------" << endl;
}
void loadWishlist()
{
ifstream wishlistFile("wishlist.txt");
if (wishlistFile.is_open()) {
int totalCustomers;
wishlistFile >> totalCustomers;
// Ensure we don't exceed MAX_CUSTOMERS
totalCustomers = min(totalCustomers, customerCount);
// Load wishlist for each customer
for (int customer = 0; customer < totalCustomers; customer++) {
int savedWishlistSize;
wishlistFile >> savedWishlistSize;
// Ensure we don't exceed MAX_WISHLIST_ITEMS
savedWishlistSize = min(savedWishlistSize, MAX_WISHLIST_ITEMS);
// Clear existing wishlist
wishlistSizes[customer] = 0;
// Read product IDs
for (int i = 0; i < savedWishlistSize; i++) {
wishlistFile >> wishlistProductIDs[customer][i];
}
// Update wishlist size
wishlistSizes[customer] = savedWishlistSize;
}
wishlistFile.close();
}
}
void saveWishlist()
{
ofstream file("wishlist.txt");
if (!file.is_open()) {
cout << "Error: Unable to open wishlist.txt for saving.\n";
return;
}
// Write the total number of customers
file << customerCount << '\n';
// Save wishlist for each customer
for (int customer = 0; customer < customerCount; customer++)
{
// Write wishlist size for this customer
file << wishlistSizes[customer] << '\n';
// Write details for each wishlist entry
for (int i = 0; i < wishlistSizes[customer]; i++)
{
file << wishlistProductIDs[customer][i] << ' ';
}
file << '\n'; // End of customer's wishlist
}
file.close();
}
// Implement Remove from Wishlist
void removeFromWishlist(int customerIndex)
{
int productID;
// Check if wishlist is empty
if (wishlistSizes[customerIndex] == 0)
{
cout << "\n====================================" << endl;
cout << " Your Wishlist is Empty " << endl;
cout << "====================================" << endl;
return;
}
// Prompt for product ID to remove
cout << "\n====================================" << endl;
cout << " Remove from Wishlist " << endl;
cout << "====================================" << endl;
cout << "\n\tEnter Product ID to remove from wishlist: ";
cin >> productID;
// Find and remove the product
for (int i = 0; i < wishlistSizes[customerIndex]; i++)
{
if (wishlistProductIDs[customerIndex][i] == productID) {
// Shift remaining items
for (int j = i; j < wishlistSizes[customerIndex] - 1; j++)
{
wishlistProductIDs[customerIndex][j] = wishlistProductIDs[customerIndex][j + 1];
}
wishlistSizes[customerIndex]--;
cout << "\n====================================" << endl;