-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsproject.cpp
More file actions
2731 lines (2386 loc) · 85.5 KB
/
Copy pathdsproject.cpp
File metadata and controls
2731 lines (2386 loc) · 85.5 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 <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <conio.h>
#include <climits>
using namespace std;
void restaurantsLocation() {
cout << "\nLOCATIONS: \n";
cout << "0 F-5 | 8 G-5 | 18 H-8 | 22 I-8" << endl;
cout << "1 F-6 | 9 G-6 | 19 H-9 | 23 I-9" << endl;
cout << "2 F-7 | 10 G-7 | 20 H-10 | 24 I-10" << endl;
cout << "3 F-8 | 11 G-8 | 21 H-11 | 25 I-11" << endl;
cout << "4 F-9 | 12 G-9 | | 26 I-12" << endl;
cout << "5 F-10 | 13 G-10 | | 27 I-14" << endl;
cout << "6 F-11 | 14 G-11 | | 28 I-15" << endl;
cout << " | 15 G-12 | | 29 I-16" << endl;
cout << " | 16 G-13 | |" << endl;
cout << " | 17 G-14 | |" << endl;
}
void convertToLoc(int index) {
if (index >= 0 && index <= 7) {
cout << "F-" << (5 + index) << endl; // Start at F-5 and add the index to get the right value
}
else if (index >= 8 && index <= 17) {
cout << "G-" << (index - 3) << endl;
}
else if (index >= 18 && index <= 21) {
cout << "H-" << (index - 10) << endl;
}
else if (index >= 22 && index <= 29) {
cout << "I-";
index -= 14;
if (index >= 13) cout << (index + 1) << endl;
else cout << (index) << endl;
}
else {
cout << "Invalid ";
}
}
class Graph {
int V;
int** adj;
public:
Graph(int vertices) {
V = vertices;
adj = new int* [V];
for (int i = 0; i < V; i++) {
adj[i] = new int[V];
for (int j = 0; j < V; j++) {
adj[i][j] = (i == j) ? 0 : INT_MAX;
}
}
}
void addEdge(int u, int v, int weight) {
if (u < 0 || u >= V || v < 0 || v >= V || weight < 0) {
cout << "Invalid edge or weight!" << endl;
return;
}
adj[u][v] = weight;
adj[v][u] = weight;
}
void printPath(int predecessors[], int current) {
if (current == -1) return; // Base case: no predecessor
//predecessor akaparent node storing array
printPath(predecessors, predecessors[current]);
convertToLoc(current);
}
void shortestPath(int src, int dests[], int destCount) {
int* dist = new int[V]; // Distance array
bool* visited = new bool[V]; // Visited array
int* predecessors = new int[V]; // To store the path
for (int i = 0; i < V; i++) {
dist[i] = INT_MAX;
visited[i] = false;
predecessors[i] = -1; // -1 indicates no predecessor
}
dist[src] = 0;
for (int count = 0; count < V - 1; count++) {
int u = -1;
// Find the minimum distance vertex not yet visited
for (int i = 0; i < V; i++) {
if (!visited[i] && (u == -1 || dist[i] < dist[u])) {
u = i;
}
}
// If no vertex was found, break
if (u == -1) break;
// Mark the chosen vertex as visited
visited[u] = true;
// Update distances of adjacent vertices
for (int v = 0; v < V; v++) {
// Check if v is reachable from u
if (!visited[v] && adj[u][v] != INT_MAX && dist[u] != INT_MAX &&
dist[u] + adj[u][v] < dist[v]) {
dist[v] = dist[u] + adj[u][v];
predecessors[v] = u; // Set predecessor of v to u
}
}
}
// Sorting the destinations based on their distance from src (bubble sort)
for (int i = 0; i < destCount - 1; i++) {
for (int j = i + 1; j < destCount; j++) {
if (dist[dests[i]] > dist[dests[j]]) {
int temp = dests[i];
dests[i] = dests[j];
dests[j] = temp;
}
}
}
for (int i = 0; i < destCount; i++) {
int dest = dests[i];
if (dist[dest] == INT_MAX) {
cout << "No path to node " << dest << "\n";
}
else {
cout << "Shortest path to node " << dest << ": ";
printPath(predecessors, dest);
cout << "\nTotal weight: " << dist[dest] << "\n\n";
}
}
delete[] dist;
delete[] visited;
delete[] predecessors;
}
~Graph() {
for (int i = 0; i < V; i++) {
delete[] adj[i];
}
delete[] adj;
}
};
void initializeGraph(Graph& g) {
g.addEdge(0, 3, 15); //f-5 to f-8
g.addEdge(0, 5, 2); //f-5 to f-10
g.addEdge(0, 29, 7); //f-5 to i-16
g.addEdge(0, 7, 2); //f-5 to f-12
g.addEdge(0, 24, 15);//f-5 to i-10
g.addEdge(1, 7, 13);//f-6 to f-12
g.addEdge(1, 28, 8);//f-6 to i-15
g.addEdge(1, 23, 3);//f-6 to i-9
g.addEdge(1, 26, 9);//f-6 to i-12
g.addEdge(1, 5, 3);//f-6 to f-10
g.addEdge(1, 3, 7);//f-6 to f-8
g.addEdge(1, 19, 12);//f-6 to h-9
g.addEdge(2, 12, 15);//f-7 tp g-9
g.addEdge(2, 29, 5);//f-7 tp i-16
g.addEdge(2, 5, 6);//f-7 tp f-10
g.addEdge(3, 15, 4);//f-8 to g-12
g.addEdge(3, 25, 4);//f-8 to i-11
g.addEdge(3, 7, 6);//f-8 to f-12
g.addEdge(3, 12, 4);//f-8 to g-9
g.addEdge(4, 7, 9);//f-9 to f-12
g.addEdge(4, 21, 10);//f-9 to h-11
g.addEdge(4, 13, 3);//f-9 to g-10
g.addEdge(4, 25, 8);//f-9 to i-11
g.addEdge(4, 19, 11);//f-9 to h-9
g.addEdge(4, 9, 15);//f-9 to g-6
g.addEdge(4, 28, 7);//f-9 to i-15
g.addEdge(4, 29, 9);//f-9 to i-16
g.addEdge(5, 6, 6);//f-10 to f-11
g.addEdge(5, 13, 13);//f-10 to g-10
g.addEdge(5, 14, 5);//f-10 to g-11
g.addEdge(6, 23, 14);//f-11 to i-9
g.addEdge(6, 8, 1);//f-11 to g-5
g.addEdge(6, 13, 1);//f-11 to g-10
g.addEdge(6, 12, 11);//f-11 to g-9
g.addEdge(6, 19, 5);//f-11 to h-9
g.addEdge(7, 9, 12); //f-12 to g-6
g.addEdge(7, 11, 7); //f-12 to g-8
g.addEdge(7, 29, 1); //f-12 to i-16
g.addEdge(7, 27, 13); //f-12 to i-14
g.addEdge(7, 13, 5); //f-12 to g-10
g.addEdge(7, 28, 14); //f-12 to i-15
g.addEdge(7, 21, 3); //f-12 to h-11
g.addEdge(8, 18, 11);//g-5 to h-8
g.addEdge(8, 27, 12);//g-5 to i-14
g.addEdge(9, 27, 2);//g-6 to i-14
g.addEdge(10, 21, 1);//g-7 to h-11
g.addEdge(10, 19, 2);//g-7 to h-9
g.addEdge(10, 11, 2);//g-7 to g-8
g.addEdge(11, 19, 6);//g-8 to h-9
g.addEdge(11, 23, 5);//g-8 to i-9
g.addEdge(11, 22, 10);//g-8 to i-8
g.addEdge(12, 17, 12);//g-9 to g-14
g.addEdge(12, 21, 7);//g-9 to h-11
// g-10 == 13
g.addEdge(14, 27, 1);//g-11 to i-14
g.addEdge(14, 22, 10);//g-11 to i-8
g.addEdge(14, 18, 6);//g-11 to h-8
g.addEdge(14, 23, 9);//g-11 to i-9
g.addEdge(15, 19, 8);//g-12 to h-9
g.addEdge(15, 28, 3);//g-12 to i-15
g.addEdge(15, 17, 14);//g-12 to g-14
g.addEdge(15, 26, 15);//g-12 to i-12
g.addEdge(15, 21, 4);//g-12 to h-11
g.addEdge(15, 23, 7);//g-12 to i-9
g.addEdge(15, 25, 12);//g-12 to i-11
g.addEdge(16, 21, 1);//g-13 to h-11
g.addEdge(17, 29, 2);//g-14 to i-16
g.addEdge(17, 26, 8);//g-14 to i-12
g.addEdge(18, 24, 2);//h-8 to i-10
g.addEdge(18, 26, 9);//h-8 to i-12
g.addEdge(18, 29, 13);//h-8 to i-16
g.addEdge(19, 22, 3);//h-9 to i-8
g.addEdge(19, 24, 3);//h-9 to i-10
g.addEdge(20, 23, 4);//h-10 to i-9
g.addEdge(20, 24, 5);//h-10 to i-10
g.addEdge(20, 22, 5);//h-10 to i-8
g.addEdge(21, 27, 2);//h-11 to i-14
g.addEdge(21, 28, 5);//h-11 to i-15
g.addEdge(21, 26, 9);//h-11 to i-12
g.addEdge(22, 28, 2);//i-8 to i-15
g.addEdge(23, 25, 7);//i-9 to i-11
g.addEdge(23, 26, 8);//i-9 to i-12
g.addEdge(24, 29, 14);//i-10 to i-16
//i-11 == 25
g.addEdge(26, 28, 6);//i-12 to i-15
g.addEdge(26, 27, 8);//i-12 to i-14
//i-14 == 27
//i-15 == 28
//i-16 == 29
}
struct Promotion;
class PromotionStack;
class Employee;
class Restaurant;
class EmployeeHashTable;
class Customer;
class CustomerHashTable;
class Order;
void applyPromotion(PromotionStack* promo, Order* newOrder);
struct Dish {
string ID;
string name;
string type;
int cost;
Dish* left;
Dish* right;
Dish(int ID, string name, string type, int cost)
: name(name), type(type), cost(cost), left(nullptr), right(nullptr) {
this->ID = to_string(ID);
while (this->ID.length() < 5) {
this->ID = "0" + this->ID;
}
}
};
class Menu {
string resName;
Dish* root;
public:
Menu() : root(nullptr) {}
Menu(string restaurantName) : resName(restaurantName), root(nullptr) {}
// Add a dish to the tree
void addDish() {
string dishName, type;
int cost;
cout << "Enter Dish Name: ";
cin.ignore();
getline(cin, dishName);
// Check if dish with this name already exists.
if (isNameDuplicate(root, dishName)) {
cout << "Dish with the name \"" << dishName << "\" already exists.\n";
return;
}
cout << "Enter Dish Type: ";
getline(cin, type);
cout << "Enter Dish Cost: ";
cin >> cost;
int newID = getNextID();
Dish* newDish = new Dish(newID, dishName, type, cost);
if (!root) {
root = newDish;
}
else {
addDishToTree(root, newDish);
}
cout << "Dish added successfully with ID: " << newDish->ID << endl;
}
// Edit a dish in the tree
void editDish() {
string ID;
cout << "Enter Dish ID to edit: ";
cin >> ID;
Dish* dish = findDish(root, ID);
if (dish) {
cout << "Editing Dish - ID: " << dish->ID << ", Name: " << dish->name
<< ", Type: " << dish->type << ", Cost: " << dish->cost << endl;
string newName, newType;
int newCost;
cout << "Enter new Dish Name: ";
cin.ignore();
getline(cin, newName);
// Check for duplicate name if changed
if (newName != dish->name && isNameDuplicate(root, newName)) {
cout << "Dish with the name \"" << newName << "\" already exists.\n";
return;
}
cout << "Enter new Dish Type: ";
getline(cin, newType);
cout << "Enter new Dish Cost: ";
cin >> newCost;
dish->name = newName;
dish->type = newType;
dish->cost = newCost;
cout << "Dish updated successfully.\n";
}
else {
cout << "Dish with ID " << ID << " not found.\n";
}
}
// Delete a dish from the tree
void deleteDish() {
string ID;
cout << "Enter Dish ID to delete: ";
cin >> ID;
root = deleteDishFromTree(root, ID);
}
// Display dishes (In-Order Traversal)
void displayDishes() const {
if (!root) {
cout << "No dishes to display.\n";
return;
}
cout << "Restaurant: " << resName << "\nDish Menu:\n";
displayTreeInOrder(root);
}
Dish* searchDish(const string& dishID) const {
return findDish(root, dishID);
}
// Helper to get the next unique ID
int getNextID() {
static int currentID = 1;
return currentID++;
}
// Check for duplicate dish names
bool isNameDuplicate(Dish* node, const string& name) const {
if (!node) return false;
if (node->name == name) return true;
return isNameDuplicate(node->left, name) || isNameDuplicate(node->right, name);
}
// Recursive helper to add a dish to the tree
void addDishToTree(Dish* node, Dish* newDish) {
if (newDish->ID < node->ID) {
if (node->left) {
addDishToTree(node->left, newDish);
}
else {
node->left = newDish;
}
}
else {
if (node->right) {
addDishToTree(node->right, newDish);
}
else {
node->right = newDish;
}
}
}
// Recursive helper to find a dish by ID
Dish* findDish(Dish* node, const string& ID) const {
if (!node) return nullptr;
if (node->ID == ID) return node;
if (ID < node->ID) return findDish(node->left, ID);
return findDish(node->right, ID);
}
// Recursive helper to delete a dish from the tree
Dish* deleteDishFromTree(Dish* node, const string& ID) {
if (!node) return nullptr;
if (ID < node->ID) {
node->left = deleteDishFromTree(node->left, ID);
}
else if (ID > node->ID) {
node->right = deleteDishFromTree(node->right, ID);
}
else {
// Node to be deleted found
if (!node->left) {
Dish* rightChild = node->right;
delete node;
return rightChild;
}
else if (!node->right) {
Dish* leftChild = node->left;
delete node;
return leftChild;
}
else {
// Find the smallest node in the right subtree
Dish* successor = node->right;
while (successor && successor->left) {
successor = successor->left;
}
// Copy successor data
node->ID = successor->ID;
node->name = successor->name;
node->type = successor->type;
node->cost = successor->cost;
// Delete successor
node->right = deleteDishFromTree(node->right, successor->ID);
}
}
return node;
}
// Recursive In-Order Traversal
void displayTreeInOrder(Dish* node) const {
if (!node) return;
displayTreeInOrder(node->left);
cout << "ID: " << node->ID << ", Dish: " << node->name
<< ", Type: " << node->type << ", Cost: " << node->cost << endl;
displayTreeInOrder(node->right);
}
};
class Employee {
public:
int nextID = 0;
string ID;
string name;
string role;
string password;
Employee* next;
Employee(int ID = 0, string name = "", string role = "", string password = "") : name(name), password(password), role(role), next(nullptr) {
this->ID = to_string(ID);
while (this->ID.length() < 5) {
this->ID = "0" + this->ID;
}
}
Employee(string id = "", const string& name = "", const string& role = "", const string& password = "")
: ID(id), name(name), role(role), password(password), next(nullptr) {}
void display() {
cout << "ID: " << ID << ", Name: " << name << ", Role: " << role << endl;
}
};
class EmployeeHashTable {
public:
static const int table_size = 100;
Employee* hashTable[table_size];
int nextID;
// Constructor
EmployeeHashTable() : nextID(1) {
for (int i = 0; i < table_size; i++) {
hashTable[i] = nullptr;
}
}
// Generate a new unique employee ID
string generateID() {
string id = to_string(nextID++);
while (id.length() < 5) {
id = "0" + id;
}
return id;
}
// Hash function to map ID to table index
int hashFunction(string id) {
int num = stoi(id);
return (num % table_size);
}
// Add an employee to the hash table
void addEmployee(string id, const string& name, const string& role, const string& password) {
cout << "Adding Employee with ID: " << id << endl;
int index = hashFunction(id);
Employee* newEmployee = new Employee(id, name, role, password);
if (hashTable[index] == nullptr) {
hashTable[index] = newEmployee;
}
else {
Employee* current = hashTable[index];
while (current->next != nullptr) {
current = current->next;
}
current->next = newEmployee;
}
}
// Search for an employee by ID
Employee* searchEmployee(string id) {
int index = hashFunction(id);
Employee* current = hashTable[index];
while (current != nullptr) {
if (current->ID == id) {
return current; // Employee found
}
current = current->next;
}
return nullptr; // Employee not found
}
// Delete an employee by ID
void deleteEmployee(string id) {
int index = hashFunction(id);
Employee* current = hashTable[index];
Employee* prev = nullptr;
// Search for the employee to delete
while (current != nullptr) {
if (current->ID == id) {
if (prev == nullptr) { // Employee is the first in the chain
hashTable[index] = current->next;
}
else {
prev->next = current->next;
}
delete current;
cout << "Employee with ID " << id << " deleted." << endl;
return;
}
prev = current;
current = current->next;
}
cout << "Employee with ID " << id << " not found." << endl;
}
};
class Customer {
public:
string ID;
string name;
string email;
string password;
Customer* next;
Customer(string n, string e, string p) : name(n), email(e), password(p), next(nullptr) {
static int idCounter = 00000;
ID = to_string(idCounter++);
}
Customer(string id = "", const string& name = "", const string& email = "", const string& password = "")
: ID(id), name(name), email(email), password(password), next(nullptr) {}
void editName(string newName) {
this->name = newName;
}
bool isValidPassword(string password) {
if (password.length() < 8 || password.length() > 12) { return false; }
//make bools to check all chars
bool hasUpper = false, hasLower = false, hasDigit = false, hasSpecial = false;
for (int i = 0; i < password.length(); i++) {
char ch = password[i];
if (isupper(ch)) hasUpper = true;
else if (islower(ch)) hasLower = true;
else if (isdigit(ch)) hasDigit = true;
else if (ispunct(ch)) hasSpecial = true;
}
return hasUpper && hasLower && hasDigit && hasSpecial;
}
void resetPassword(string oldPassword, string newPassword) {
if (password == oldPassword) {
if (isValidPassword(newPassword)) {
password = newPassword;
cout << "Password successfully updated." << endl;
}
else {
cout << "New password does not meet criteria." << endl;
}
}
else {
cout << "Password is incorrect." << endl;
}
}
string getId() const { return ID; }
string getEmail() const { return email; }
};
class CustomerHashTable {
public:
int nextID;
static const int table_size = 100;
Customer* chashTable[table_size];
// Constructor
CustomerHashTable() : nextID(1) {
for (int i = 0; i < table_size; i++) {
chashTable[i] = nullptr;
}
}
// Generate a new unique employee ID
string generateID() {
string id = to_string(nextID++);
while (id.length() < 5) {
id = "0" + id;
}
return id;
}
// Hash function to map ID to table index
int hashFunction(string id) {
int num = stoi(id);
return (num % table_size);
}
//to change name via hash
void editCustomerName(string customerID, const string& newName) {
Customer* customer = searchCustomer(customerID); // Locate the customer
if (customer) {
customer->editName(newName);
}
else {
cout << "Customer not found!" << std::endl;
}
}
//reset password thru hash
void resetPassword(string customerID, const string& oldPassword, const string& newPassword) {
Customer* customer = searchCustomer(customerID); // Locate the customer
if (customer) {
customer->resetPassword(oldPassword, newPassword);
}
else {
cout << "Customer not found!" << std::endl;
}
}
bool isEmailUnique(const string& email) {
for (int i = 0; i < table_size; ++i) {
Customer* current = chashTable[i];
while (current != nullptr) {
if (current->email == email) {
return false; // Email already exists
}
current = current->next;
}
}
return true;
}
// Add an employee to the hash table
void addCustomer(string id, const string& name, const string& email, const string& password) {
cout << "Adding Customer with ID: " << id << endl;
int index = hashFunction(id);
Customer* newCustomer = new Customer(id, name, email, password);
if (chashTable[index] == nullptr) {
chashTable[index] = newCustomer;
}
else {
Customer* current = chashTable[index];
while (current->next != nullptr) {
current = current->next;
}
current->next = newCustomer;
}
}
// Search for an employee by ID
Customer* searchCustomer(string id) {
int index = hashFunction(id);
Customer* current = chashTable[index];
while (current != nullptr) {
if (current->ID == id) {
return current; // Employee found
}
current = current->next;
}
return nullptr; // Employee not found
}
// Delete an employee by ID
void deleteCustomer(string id) {
int index = hashFunction(id);
Customer* current = chashTable[index];
Customer* prev = nullptr;
// Search for the employee to delete
while (current != nullptr) {
if (current->ID == id) {
if (prev == nullptr) { // Employee is the first in the chain
chashTable[index] = current->next;
}
else {
prev->next = current->next;
}
delete current;
cout << "Customer with ID " << id << " deleted." << endl;
return;
}
prev = current;
current = current->next;
}
cout << "Customer with ID " << id << " not found." << endl;
}
// Display all customers in the hash table (for testing purposes)
void displayAllCustomers() {
bool hasCustomers = false;
for (int i = 0; i < table_size; i++) {
Customer* current = chashTable[i];
while (current != nullptr) {
cout << "ID: " << current->ID << ", Name: " << current->name << ", Role: " << current->email << endl;
current = current->next;
hasCustomers = true;
}
}
if (!hasCustomers) {
cout << "No employees found." << endl;
}
}
void signup() {
string name, email, password;
cout << "Enter your name: ";
cin.ignore();
getline(cin, name);
cout << "Enter your email: ";
cin >> email;
// Check if the email is unique
if (!isEmailUnique(email)) {
cout << "This email is already in use. Please try a different one." << endl;
return;
}
// Prompt for a valid password
while (true) {
cout << "Enter a password (8-12 characters, must include uppercase, lowercase, digit, and special character): ";
//password = getPassword();
cin.ignore();
getline(cin, password);
// Check if the password meets the criteria
Customer tempCustomer;
if (tempCustomer.isValidPassword(password)) {
break;
}
else {
cout << "Password does not meet the criteria. Please try again." << endl;
}
}
string id = generateID();
// Add the new customer to the hash table
addCustomer(id, name, email, password);
cout << "Signup successful! Your Customer ID is: " << id << endl;
}
};
class OrderDishNode {
public:
Dish* dish;
OrderDishNode* next;
OrderDishNode(Dish* d) : dish(d), next(nullptr) {}
};
class Order {
public:
string ID;
string customerName;
int customerLocation;
double baseCost;
int priority; // 1 = Premium, 2 = Express, 3 = Normal
OrderDishNode* dishHead;
bool isProcessed;
bool isDelivered;
Order(string customerName, double baseCost, int priority, string ID, int customerLocation)
: customerName(customerName), baseCost(baseCost), priority(priority), ID(ID), dishHead(nullptr), isProcessed(false), isDelivered(false), customerLocation(customerLocation) {
applyDeliveryCharges();
applyPriorityCost();
}
void addDish(Dish* dish) {
OrderDishNode* newNode = new OrderDishNode(dish);
if (!dishHead) {
dishHead = newNode;
}
else {
OrderDishNode* temp = dishHead;
while (temp->next) {
temp = temp->next;
}
temp->next = newNode;
}
}
void displayOrder() {
cout << "Order ID: " << ID << "\nCustomer: " << customerName << "\nPriority: ";
if (priority == 1) cout << "Premium\n";
else if (priority == 2) cout << "Express\n";
else cout << "Normal\n";
cout << "Dishes:\n";
OrderDishNode* current = dishHead;
while (current) {
cout << "- " << current->dish->name << " (Price: " << current->dish->cost << ")\n";
current = current->next;
}
cout << "Total Cost: " << baseCost << "\n";
cout << "Order Status: " << (isProcessed ? "Processed" : "Not Processed") << "\n";
cout << "Delivery Status: " << (isDelivered ? "Delivered" : "Not Delivered") << "\n";
}
void markAsProcessed() {
isProcessed = true;
}
void markAsDelivered() {
isDelivered = true;
}
void applyPriorityCost() {
if (priority == 1) {
baseCost += 500; // Premium
}
else if (priority == 2) {
baseCost += baseCost * 0.1; // Express
}
// Normal has no extra cost
}
void applyDeliveryCharges() {
//premium has no delivery charges
if (priority == 2) {
baseCost += 200; // Express
}
else if (priority == 3) {
baseCost += 100; // Normal
}
}
};
class OrderNode {
public:
Order* ord;
OrderNode* next;
OrderNode(Order* o) : ord(o), next(nullptr) {}
};
class OrderQueue {
private:
OrderNode* head;
int idCounter;
public:
OrderQueue() : head(nullptr), idCounter(10000) {}
string generateOrderID() {
return to_string(idCounter++);
}
OrderNode* getHead() {
return head;
}
void enqueue(Order* newOrder) {
OrderNode* newNode = new OrderNode(newOrder);
//1,2,3
if (!head || newOrder->priority < head->ord->priority) {
newNode->next = head;
head = newNode;
}
else {
OrderNode* current = head;
while (current->next && current->next->ord->priority <= newOrder->priority) {
current = current->next;
}
newNode->next = current->next;
current->next = newNode;
}
}
Order* dequeue() {
OrderNode* temp = head;
// Iterate through the list to find the first unprocessed order
while (temp != nullptr) {
if (temp->ord->isProcessed == false) {
temp->ord->markAsProcessed();
return temp->ord; // Return the first unprocessed order
}
temp = temp->next; // Move to the next node
}
cout << "All orders are processed.\n";
return nullptr; // Return nullptr if all orders are processed
}
bool isEmpty() {
return head == nullptr;
}
//wil show processed unproceesed based on the argumment
void displayQueue(bool showProcessed = false) {
if (!head) {
cout << "No orders in the queue.\n";
return;
}
OrderNode* current = head;
cout << (showProcessed ? "Processed Orders:\n" : "Current Orders:\n");
while (current) {
if (current->ord->isProcessed == showProcessed) {
current->ord->displayOrder();
cout << "--------------------\n";
}