-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe.cpp
3146 lines (2770 loc) · 122 KB
/
recipe.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
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 <fstream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <cctype>
using namespace std;
// ENUMERATION FOR DIFFICULTY LEVELS
enum DifficultyLevel
{
Beginner,
Intermediate,
Advanced,
None
};
// ENUMERATION FOR RECIPE CATEGORIES
enum Category
{
Appetizer,
MainCourse,
Dessert,
Soup,
Salad,
Snack,
Breakfast,
SideDish,
Other,
Nones
};
enum Method
{
Sauteeing,
Boiling,
Blanching,
Broiling,
Stewing,
Grilling,
Baking,
Barbeque,
OvenRoasting,
Braising,
PressureCooking,
SkilletCooking,
DeepFrying,
Steaming,
StirFrying,
Others,
Noned
};
// STRUCTURE TO DEFINE INGREDIENT DETAILS
struct Ingredient
{
string name;
string unit;
};
// STRUCTURE TO DEFINE RECIPE DETAILS
struct Recipe
{
string name;
vector<Ingredient> ingredients;
vector<string> instruction;
string cooking_time;
bool isFavorite;
DifficultyLevel difficulty_level;
Category category;
Method method;
};
// FUNCTION PROTOTYPES
void header();
void saveRecipe();
void loadRecipe();
int ingredientQtyChecker();
int instructionQtyChecker();
void addRecipe();
void addRecipeItems();
void updateRecipe();
void updateRecipeItems(int num, int count);
void searchRecipe();
void deleteRecipe();
void checkExistingRecipe();
void viewRecipe(int recipeNumber);
void viewRecipeDetails(int index);
void chooseCategory();
void chooseDifficulty();
void chooseMethod();
void displayFavoriteRecipes();
void displayByCategory(Category category);
void displayByDifficulty(DifficultyLevel level);
void displayByMethod(Method method);
void addToFavorites(int index);
void removeFromFavorites(int index);
void printTabs(int tabNum);
void clearScreen();
string difficultyLevelToString(DifficultyLevel level) // FUNCTION TO CONVERT DIFFICULTY LEVEL ENUM TO STRING
{
// SWITCH STATEMENT TO HANDLE DIFFERENT LEVELS OF DIFFICULTY
switch (level)
{
case Beginner:
return "Beginner Level";
case Intermediate:
return "Intermediate Level";
case Advanced:
return "Advanced Level";
case None:
return "None";
default:
return "Unknown";
}
}
string categoryToString(Category category) // FUNCTION TO CONVERT CATEGORY ENUM TO STRING
{
// SWITCH STATEMENT TO HANDLE DIFFERENT CATEGORIES
switch (category)
{
case Appetizer:
return "Appetizer";
case MainCourse:
return "Main Course";
case Dessert:
return "Dessert";
case Soup:
return "Soup";
case Salad:
return "Salad";
case Snack:
return "Snack";
case Breakfast:
return "Breakfast";
case SideDish:
return "Side Dish";
case Other:
return "Other";
case Nones:
return "None";
default:
return "Unknown";
}
}
string methodToString(Method method) // FUNCTION TO CONVERT COOKING METHODS ENUM TO STRING
{
// SWITCH STATEMENT TO HANDLE COOKING METHODS
switch (method)
{
case Sauteeing:
return "Sauteeing";
case Boiling:
return "Boiling";
case Blanching:
return "Blanching";
case Broiling:
return "Broiling";
case Grilling:
return "Grilling";
case Baking:
return "Baking";
case Barbeque:
return "Barbeque";
case OvenRoasting:
return "Oven Roasting";
case Braising:
return "Braising";
case PressureCooking:
return "Pressure Cooking";
case SkilletCooking:
return "Skillet Cooking";
case DeepFrying:
return "Deep Frying";
case Steaming:
return "Steaming";
case StirFrying:
return "Stir Frying";
case Others:
return "Other";
case Noned:
return "None";
default:
return "Unknown";
}
}
Recipe recipes[100]; // ARRAY OF RECIPE STRUCT TO STORE MANY RECIPES
int opt = 0, count = 0;
int main()
{
loadRecipe(); // FUNCTION CALL TO LOAD RECIPES
header(); // FUNCTION CALL TO DISPLAY HEADER
clearScreen(); // FUNCTION CALL TO CLEAR SCREEN
int option; // VARIABLE TO STORE USER OPTION
while (true) // MAIN LOOP FOR MENU INTERACTION
{
clearScreen(); // FUNCTION CALL TO CLEAR SCREEN
printTabs(5); cout<<",------. ,--. ,------. ,--. \n";
printTabs(5); cout<<"| .--. ' ,---. ,---.`--' ,---. ,---. | .--. ' ,--,--.| | \n";
printTabs(5); cout<<"| '--'.'| .-. :| .--',--.| .-. || .-. :| '--' |' ,-. || | \n";
printTabs(5); cout<<"| |\\ \\ \\ --.\\ `--.| || '-' '\\ --.| | --' \\ '-' || | \n";
printTabs(5); cout<<"`--' '--' `----' `---'`--'| |-' `----'`--' `--`--'`--' \n";
printTabs(5); cout<<" `--' \n";
cout<<endl;
// RECIPE HOMEPAGE
cout<<"\033[48;2;255;255;255m";
cout<<"\033[30m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Welcome to RecipePal! "<<endl;
printTabs(5); cout<<" Organize your Recipes in an Instant "<<endl;
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" [1] Recipes Menu "<<endl;
printTabs(5); cout<<" [2] Favorite Recipes "<<endl;
printTabs(5); cout<<" [3] View Recipes by Category "<<endl;
printTabs(5); cout<<" [4] View Recipes by Difficulty "<<endl;
printTabs(5); cout<<" [5] View Recipes by Cooking Method "<<endl;
printTabs(5); cout<<" [6] Exit "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
printTabs(5); cout<<" Enter Option: ";
cin>>option;
switch (option)
{
case 1:
{
while (true) // INNER LOOP FOR RECIPES MENU
{
clearScreen(); // FUNCTION CALL TO CLEAR SCREEN
printTabs(5); cout<<",------. ,--. ,------. ,--. \n";
printTabs(5); cout<<"| .--. ' ,---. ,---.`--' ,---. ,---. | .--. ' ,--,--.| | \n";
printTabs(5); cout<<"| '--'.'| .-. :| .--',--.| .-. || .-. :| '--' |' ,-. || | \n";
printTabs(5); cout<<"| |\\ \\ \\ --.\\ `--.| || '-' '\\ --.| | --' \\ '-' || | \n";
printTabs(5); cout<<"`--' '--' `----' `---'`--'| |-' `----'`--' `--`--'`--' \n";
printTabs(5); cout<<" `--' \n";
cout<<endl;
// RECIPE MENU
cout<<"\033[48;2;255;255;255m";
cout<<"\033[30m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Welcome to RecipePal! "<<endl;
printTabs(5); cout<<" Organize your Recipes in an Instant "<<endl;
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" [1] Check Existing Recipes "<<endl;
printTabs(5); cout<<" [2] Add Recipes "<<endl;
printTabs(5); cout<<" [3] Search Recipes "<<endl;
printTabs(5); cout<<" [4] Update Recipes "<<endl;
printTabs(5); cout<<" [5] Delete Recipes "<<endl;
printTabs(5); cout<<" [6] Return to Home Page "<<endl;
printTabs(5); cout<<" [7] Exit "<<endl;
printTabs(5); cout<<" \033[0m" << endl;
cout<<endl;
printTabs(5); cout<<" Enter Option: ";
int opt;
cin>>opt;
switch(opt)
{
case 1:
checkExistingRecipe();
break;
case 2:
addRecipe();
break;
case 3:
searchRecipe();
break;
case 4:
updateRecipe();
break;
case 5:
deleteRecipe();
break;
case 6:
break; // RETURN TO OUTER MENU
case 7:
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(0);
default:
// INVALID OPTION HANDLING
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Option! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(1);
}
if (opt == 6)
{
break; // EXIT THE INNER WHILE LOOP
}
}
break;
}
case 2:
displayFavoriteRecipes();
break;
case 3:
chooseCategory(); // FUNCTION CALL TO VIEW RECIPES BY CATEGORY
break;
case 4:
chooseDifficulty(); // FUNCTION CALL TO VIEW RECIPES BY DIFFICULTY
break;
case 5:
chooseMethod(); // FUNCTION CALL TO VIEW RECIPES BY DIFFICULTY
break;
case 6:
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(0);
default:
// INVALID OPTION HANDLING
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Option! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(1);
}
}
return 0;
}
void header()
{
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"\033[32m";
printTabs(1); cout<<" @@@@+ :=*%\n";
printTabs(1); cout<<" @@@@@@@@@@@@@ @@@@@@@@@@. @@@@# +@@@@@@@@@@@ @@@@@@@@@@+\n";
printTabs(1); cout<<" @@@@@@@@@@@@@@ @@@@@@@@@@ @@@@@@@@ +@@@* .@@@@ @@@@@@@@@@\n";
printTabs(1); cout<<" @@@@+:::.@@@@@@ @@@@@% @@@@@@@@@@ @@@@ *@@@- @@@@ @@@@@@\n";
printTabs(1); cout<<" @@@@ @@@@@ @@@@@# +@@@@@@@@ @@@@* *@@@= @@@@ @@@@@@\n";
printTabs(1); cout<<" @@@@ -@@@@- @@@@@@@@@ @@@@@@ @@@@# +@@@@.+@@@@@ @@@@@@@@@\n";
printTabs(1); cout<<" @@@@ .@@@@@@ @@@@@@@@@# @@@@@ @@@@% +@@@@@@@@ @@@@@@@@@@\n";
printTabs(1); cout<<" @@@@@@@@@@@@% %@@@@@ @@@@ @@@@# =@@@@+ @@@@@@\n";
printTabs(1); cout<<" @@@@@@@@@@@@@ *@@@@@ =@@@@@ @@@@* -@@@@ @@@@@@\n";
printTabs(1); cout<<" @@@@@ @@@@@@ -@@@@@ @@@@@@@@@%- @@@@* :@@@% @@@@@@\n";
printTabs(1); cout<<" @@@@@ @@@@@ @@@@@@@@@@@% +@@@@@@@@@: @@@@* :@@@* @@@@@@@@@@*\n";
printTabs(1); cout<<" @@@@@ @@@@@ @@@@@@@@@@% @@@@@@@ @@@@* .@@@+ *@@@@@@@@@\n";
printTabs(1); cout<<" @@\n";
cout<<"\033[0m";
cout<<endl;
cout<<endl;
printTabs(1); cout<<" @@@@@@@@@\n";
printTabs(1); cout<<" @@@@@@@@@@@@ @@@@@@ @@@@@:\n";
printTabs(1); cout<<" @@@@ @@@- +@@@@@@. @@@@@\n";
printTabs(1); cout<<" @@@@ @@@@ @@@@@@@@ @@@@@\n";
printTabs(1); cout<<" @@@@ @@@@ @@@@ @@@@ @@@@@\n";
printTabs(1); cout<<" @@@@@@@@@@ @@@@@ @@@@ %@@@@\n";
printTabs(1); cout<<" @@@@@@@ @@@@@ @@@@@ *@@@@\n";
printTabs(1); cout<<" @@@@+ :@@@@@@@@@@@@- +@@@@\n";
printTabs(1); cout<<" @@@@: @@@@@@@@%*@@@@ +@@@@\n";
printTabs(1); cout<<" @@@@. @@@@ @@@@ *@@@@@@@@@@@\n";
printTabs(1); cout<<" @@@@ @@@@ -@@@. %@@@@@@@@@@@\n";
printTabs(1); cout<<" *@@ -+% =@@@@@@@@@@@\n";
cout<<endl;
printTabs(7); cout<<"Press Enter to continue...";
cin.get();
}
void saveRecipe()
{
// OPEN FILE STREAM FOR WRITING
ofstream write("recipes.txt");
if (!write.is_open())
{
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Unable to open file! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
return;
}
// WRITE THE TOTAL COUNT OF RECIPES
write<<count<<endl;
// LOOP THROUGH EACH RECIPE
for (int i = 0; i < count; i++)
{
// WRITE RECIPE NAME
write<<recipes[i].name<<"|";
// WRITE NUMBER OF INGREDIENTS
write<<recipes[i].ingredients.size()<<"|";
// WRITE EACH INGREDIENT
for (size_t j = 0; j < recipes[i].ingredients.size(); j++)
{
write<<recipes[i].ingredients[j].name<<"|";
write<<recipes[i].ingredients[j].unit<<"|";
}
// WRITE NUMBER OF INSTRUCTION STEPS
write<<recipes[i].instruction.size()<<"|";
// WRITE EACH INSTRUCTION STEP
for (size_t j = 0; j < recipes[i].instruction.size(); j++)
{
write<<recipes[i].instruction[j]<<"|";
}
// WRITE COOKING TIME, DIFFICULTY LEVEL, CATEGORY, AND FAVORITE STATUS
write<<recipes[i].cooking_time<<"|";
write<<static_cast<int>(recipes[i].difficulty_level)<<"|";
write<<static_cast<int>(recipes[i].category)<<"|";
write<<static_cast<int>(recipes[i].method)<<"|";
write<<(recipes[i].isFavorite ? 1 : 0)<<endl;
}
// CLOSE THE FILE STREAM
write.close();
}
void loadRecipe()
{
// OPEN FILE STREAM FOR READING
ifstream read("recipes.txt");
if (!read.is_open())
{
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Unable to open file! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
return;
}
// READ THE TOTAL COUNT OF RECIPES
read>>count;
read.ignore(); // Ignore the newline character left by '>>'
// LOOP THROUGH EACH RECIPE
for (int i = 0; i < count; i++)
{
// READ RECIPE NAME
getline(read, recipes[i].name, '|');
// READ NUMBER OF INGREDIENTS
int ingredients_qty;
read>>ingredients_qty;
read.ignore(); // Ignore the '|' character
recipes[i].ingredients.resize(ingredients_qty);
// READ EACH INGREDIENT
for (int j = 0; j < ingredients_qty; j++)
{
getline(read, recipes[i].ingredients[j].name, '|');
getline(read, recipes[i].ingredients[j].unit, '|');
}
// READ NUMBER OF INSTRUCTION STEPS
int instruction_qty;
read>>instruction_qty;
read.ignore(); // Ignore the '|' character
recipes[i].instruction.resize(instruction_qty);
// READ EACH INSTRUCTION STEP
for (int j = 0; j < instruction_qty; j++)
{
getline(read, recipes[i].instruction[j], '|');
}
// READ COOKING TIME, DIFFICULTY LEVEL, AND CATEGORY
getline(read, recipes[i].cooking_time, '|');
int difficultyLevel;
read >> difficultyLevel; // Read the difficulty level as integer
read.ignore(); // Consume the newline left by '>>'
recipes[i].difficulty_level = static_cast<DifficultyLevel>(difficultyLevel);
int category;
read >> category; // Read the category as integer
read.ignore(); // Ignore the '|' character
recipes[i].category = static_cast<Category>(category);
int method;
read >> method; // Read the category as integer
read.ignore(); // Ignore the '|' character
recipes[i].method = static_cast<Method>(method);
int isFavoriteInt;
read >> isFavoriteInt;
read.ignore(); // Ignore the newline character
recipes[i].isFavorite = (isFavoriteInt == 1);
}
// CLOSE THE FILE STREAM
read.close();
}
int ingredientQtyChecker() // FUNCTION VALIDATES AMD RETRIEVES NUMBER OF INGREDIENTS ENSURING IT IS POSITIVE
{
int ingredients_qty;
bool validInput = false;
// LOOP UNTIL VALID INPUT IS RECEIVED
while (!validInput)
{
printTabs(5); cout<<" No. of Ingredients: ";
cin>>ingredients_qty;
// CHECK FOR INVALID INPUT (NON-INTEGER OR NEGATIVE VALUE)
if (cin.fail() || ingredients_qty <= 0)
{
cin.clear(); // CLEAR ERROR FLAG
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // DISCARD INVALID INPUT
// DISPLAY ERROR MESSAGE
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid input for Ingredients Quantity! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
}
else
{
validInput = true; // SET FLAG TO EXIT LOOP
}
}
cin.ignore(); // CLEAR THE NEWLINE CHARACTER LEFT IN THE BUFFER
return ingredients_qty; // RETURN VALID INPUT
}
int instructionQtyChecker() // FUNCTION VALIDATES AMD RETRIEVES NUMBER OF INSTRUCTIONS ENSURING IT IS POSITIVE
{
int instruction_qty;
bool validInput = false;
// LOOP UNTIL VALID INPUT IS RECEIVED
while (!validInput)
{
printTabs(5); cout<<" No. of Instruction Steps: ";
cin >> instruction_qty;
// CHECK FOR INVALID INPUT (NON-INTEGER OR NEGATIVE VALUE)
if (cin.fail() || instruction_qty <= 0)
{
cin.clear(); // CLEAR ERROR FLAG
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // DISCARD INVALID INPUT
// DISPLAY ERROR MESSAGE
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout << " "<<endl;
printTabs(5); cout << " Invalid input for Instruction Steps Quantity! "<<endl;
printTabs(5); cout << " \033[0m"<<endl;
cout<<endl;
}
else
{
validInput = true; // SET FLAG TO EXIT LOOP
}
}
cin.ignore(); // CLEAR THE NEWLINE CHARACTER LEFT IN THE BUFFER
return instruction_qty; // RETURN VALID INPUT
}
void addRecipe() // FUNCTION TO ALLOW USERS TO ADD RECIPE
{
clearScreen(); // CLEAR THE SCREEN FOR A CLEAN INTERFACE
cout<<"\033[46m";
cout<<"\033[97m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Add Recipe "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
addRecipeItems(); // CALL FUNCTION TO ADD RECIPE ITEMS
// CONFIRMATION MESSAGE
cout<<endl;
cout<<"\033[97m";
cout<<"\033[42m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Recipe Added Successfully! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
printTabs(6); cout << " Press Enter to continue...";
cin.ignore(); // WAIT FOR USER TO PRESS ENTER TO CONTINUE
cin.get();
viewRecipe(count); // DISPLAY THE RECIPE DETAILS (COUNT INDICATES INDEX OF THE NEWLY ADDED RECIPE)
addToFavorites(count - 1); // ADD THE NEWLY ADDED RECIPE TO FAVORITES
// OPTIONS FOR USER
cout<<endl;
cout<<"\033[47m";
cout<<"\033[30m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" [1] Add another Recipe "<<endl;
printTabs(5); cout<<" [2] Back to Recipe Menu "<<endl;
printTabs(5); cout<<" [3] Exit the Program "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
printTabs(5); cout<<" Enter Option: ";
int option;
cin>>option;
switch (option)
{
case 1:
addRecipe(); // RECURSIVELY CALL THIS FUNCTION TO ADD ANOTHER RECIPE
break;
case 2:
return; // RETURN TO THE CALLING FUNCTION OR LOOP
case 3:
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(0); // EXIT THE PROGRAM
default:
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Option! "<<endl; // DISPLAY ERROR MESSAGE FOR INVALID OPTION
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(1); // EXIT THE PROGRAM
}
}
void addRecipeItems() // FUNCTION GUIDES THE USER THROUGH ENTERING DETAILS FOR NEW RECIPE
{
cin.ignore(); // CLEAR THE INPUT BUFFER
printTabs(5); cout<<" Recipe Name: ";
getline(cin, recipes[count].name);
int ingredients_qty = ingredientQtyChecker(); // CALL FUNCTION TO GET NUMBER OF INGREDIENTS
recipes[count].ingredients.resize(ingredients_qty); // RESIZE TO ACCOMMODATE ingredients_qty
// PROMPT FOR EACH INGREDIENT
for (int i = 0; i < ingredients_qty; ++i)
{
printTabs(5); cout<<" Ingredient "<< i + 1 <<":"<<endl;
printTabs(5); cout<<" Name: ";
getline(cin, recipes[count].ingredients[i].name);
printTabs(5); cout<<" Unit: ";
getline(cin, recipes[count].ingredients[i].unit);
}
int instruction_qty = instructionQtyChecker(); // CALL FUNCTION TO GET NUMBER OF INSTRUCTION STEPS
recipes[count].instruction.resize(instruction_qty); // RESIZE TO ACCOMMODATE instruction_qty
// PROMPT FOR EACH INSTRUCTION STEP
for (int i = 0; i < instruction_qty; ++i)
{
printTabs(5); cout<< " Step "<< i + 1 <<": ";
getline(cin, recipes[count].instruction[i]);
}
printTabs(5); cout<<" Cooking Time: ";
getline(cin, recipes[count].cooking_time);
cout<<endl;
printTabs(5); cout<<" Select Cooking Difficulty Level:"<<endl;
printTabs(5); cout<<" [1] Beginner Level [2] Intermediate Level [3] Advanced Level"<<endl;
printTabs(5); cout<<" Enter Option: ";
int difficultyOption;
cin>>difficultyOption;
cin.ignore();
// ASSIGN COOKING DIFFICULTY BASED ON USER INPUT
switch (difficultyOption)
{
case 1:
recipes[count].difficulty_level = Beginner;
break;
case 2:
recipes[count].difficulty_level = Intermediate;
break;
case 3:
recipes[count].difficulty_level = Advanced;
break;
default:
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Option! "<<endl;
printTabs(5); cout<<" Setting difficulty to Beginner by default. "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
recipes[count].difficulty_level = Beginner; // SET DEFAULT TO BEGINNER LEVEL
break;
}
// PROMPT FOR RECIPE CATEGORY
cout<<endl;
printTabs(5); cout<<" Select Category:"<<endl;
printTabs(5); cout<<" [1] Appetizer [3] Dessert [5] Snack [7] SideDish"<<endl;
printTabs(5); cout<<" [2] Main Course [4] Soup [6] Breakfast [8] Other"<<endl;
printTabs(5); cout<<" Enter Option: ";
int categoryOption;
cin>>categoryOption;
cin.ignore(); // CONSUME NEWLINE LEFT BY cin
// ASSIGN RECIPE CATEGORY BASED ON USER INPUT
switch (categoryOption)
{
case 1:
recipes[count].category = Appetizer;
break;
case 2:
recipes[count].category = MainCourse;
break;
case 3:
recipes[count].category = Dessert;
break;
case 4:
recipes[count].category = Soup;
break;
case 5:
recipes[count].category = Snack;
break;
case 6:
recipes[count].category = Breakfast;
break;
case 7:
recipes[count].category = SideDish;
break;
case 8:
recipes[count].category = Other;
break;
default:
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Option! "<<endl;
printTabs(5); cout<<" Setting category to Other by default. "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
recipes[count].category = Other; // SET DEFAULT TO OTHER CATEGORY
break;
}
// PROMPT FOR RECIPE COOKING METHOD
cout<<endl;
printTabs(5); cout<<" Select Cooking Method:"<<endl;
printTabs(5); cout<<" [1] Sauteeing [5] Stewing [9] Oven Roasting [13] Deep Frying"<<endl;
printTabs(5); cout<<" [2] Boiling [6] Grilling [10] Braising [14] Steaming"<<endl;
printTabs(5); cout<<" [3] Blanching [7] Baking [11] Pressure Cooking [15] Stir Frying"<<endl;
printTabs(5); cout<<" [4] Broiling [8] Barbeque [12] Skillet Cooking [16] Other"<<endl;
printTabs(5); cout<<" Enter Option: ";
int methodOption;
cin>>methodOption;
cin.ignore(); // CONSUME NEWLINE LEFT BY cin
// ASSIGN RECIPE CATEGORY BASED ON USER INPUT
switch (methodOption)
{
case 1:
recipes[count].method = Sauteeing;
break;
case 2:
recipes[count].method = Boiling;
break;
case 3:
recipes[count].method = Blanching;
break;
case 4:
recipes[count].method = Broiling;
break;
case 5:
recipes[count].method = Stewing;
break;
case 6:
recipes[count].method = Grilling;
break;
case 7:
recipes[count].method = Baking;
break;
case 8:
recipes[count].method = Barbeque;
break;
case 9:
recipes[count].method = OvenRoasting;
break;
case 10:
recipes[count].method = Braising;
break;
case 11:
recipes[count].method = PressureCooking;
break;
case 12:
recipes[count].method = SkilletCooking;
break;
case 13:
recipes[count].method = DeepFrying;
break;
case 14:
recipes[count].method = Steaming;
break;
case 15:
recipes[count].method = StirFrying;
break;
case 16:
recipes[count].method = Others;
break;
default:
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Option! "<<endl;
printTabs(5); cout<<" Setting cooking method to Other by default. "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
recipes[count].method = Others; // SET DEFAULT TO OTHER CATEGORY
break;
}
count++; // INCREMENT RECIPE COUNT
saveRecipe(); // SAVE THE RECIPE TO FILE
loadRecipe(); // RELOAD RECIPES TO UPDATE count VARIABLE
}
void updateRecipe() // FUNCTION TO ALLOW USER TO UPDATE RECIPE
{
// OPEN THE FILE TO READ
ifstream file("recipes.txt");
// CHECK IF THE FILE IS OPEN
if (!file.is_open())
{
// DISPLAY ERROR MESSAGE IF FILE CANNOT BE OPENED
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Unable to open file! "<<endl;
printTabs(5); cout<<" Please check the file path! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
// WAIT FOR USER INPUT
printTabs(6); cout<<" Press Enter to continue...";
cin.ignore();
cin.get();
// CLOSE THE FILE (ALTHOUGH IT'S NOT OPEN)
file.close();
return;
}
// CLEAR THE SCREEN AND LOAD RECIPES FROM FILE
clearScreen();
loadRecipe();
// DISPLAY UPDATE INTERFACE HEADER
cout<<"\033[46m";
cout<<"\033[97m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Update Recipe "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
// DISPLAY EXISTING RECIPES
printTabs(5); cout<<" Existing Recipes:"<<endl;
for (int i = 0; i < count; i++)
{
printTabs(5); cout<<" "<< i + 1 <<". "<<recipes[i].name<<endl;
}
int num = 0;
cout<<endl;
printTabs(5); cout<<" Enter Recipe Number to Update: ";
cin>>num;
// VALIDATE USER INPUT FOR RECIPE NUMBER
if (num < 1 || num > count)
{
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Recipe Number! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
printTabs(6); cout<<" Press Enter to continue..."<<endl;
cin.ignore();
cin.get();
return;
}
int index = num - 1;
// CALL FUNCTION TO UPDATE RECIPE ITEMS
updateRecipeItems(index, num);
cout<<endl;
cout<<"\033[47m";
cout<<"\033[30m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" [1] Update another Recipe "<<endl;
printTabs(5); cout<<" [2] Back to Recipe Menu "<<endl;
printTabs(5); cout<<" [3] Exit the Program "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
int option;
printTabs(5); cout<<" Enter Option: ";
cin>>option;
switch (option)
{
case 1:
// UPDATE ANOTHER RECIPE
updateRecipe();
break;
case 2:
// RETURN TO RECIPE MENU
return;
case 3:
// EXIT THE PROGRAM
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(0);
default:
cout<<endl;
cout<<"\033[97m";
cout<<"\033[41m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Invalid Choice! "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
// EXIT THE PROGRAM WITH ERROR
printTabs(5); cout<<" Exiting the program..."<<endl;
exit(1);
}
}
void updateRecipeItems(int index, int num) // FUNCTION GUIDES THE USER THROUGH ENTERING DETAILS FOR UPDATED RECIPE
{
clearScreen();
cout<<"\033[46m";
cout<<"\033[97m";
printTabs(5); cout<<" "<<endl;
printTabs(5); cout<<" Update Recipe "<<endl;
printTabs(5); cout<<" \033[0m"<<endl;
cout<<endl;
// DISPLAY EXISTING RECIPE DETAILS
printTabs(5); cout<<" Existing Recipe Details:"<<endl;
// VIEW CURRENT RECIPE
viewRecipe(num);