-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedlist.h
5138 lines (4523 loc) · 136 KB
/
linkedlist.h
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
#pragma once
#include <iostream>
#include <string>
#include <sstream> //convert datatypes like address, double into string
#include <ctype.h> //for input validation: isdigit()
#include <ctime> //for date format validation
#include <algorithm> //for uppercase the input for easing future search
#include <vector> //for the usage of splitting string by delimiter
//sleep functions
#include <chrono>
#include <thread>
// to avoid error in line 520 due to Visual Studio suggesting the other alternative and halt the system when the code is working well
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable : 4996)
// to define a macro to call out the length of the array
#define arrayLength(array) (sizeof((array))/sizeof((array)[0]))
/* global variables */
// array for displaying rating description
std::string ratingdescription[5] = { "Very Poor Performance", "Below Average", "Average", "Above Average", "Excellent Performance" };
// array for displaying numbers in english
std::string numberenglish[11] = { "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten",
"eleven" };
// array for table titles
std::string tabletitle[11] = { "Tutor ID", "Name", "Date Joined", "Date Terminated", "Hourly Rate (RM)",
"Phone", "Address", "Tuition Centre Code", "Tuition Centre Name", "Subject",
"Rating" };
// pointer format on those array so we can call the value within them
// pointer format of table titles
std::string * tabletitlepointer = new std::string[11]{ "Tutor ID", "Name", "Date Joined", "Date Terminated", "Hourly Rate (RM)",
"Phone", "Address", "Tuition Centre Code", "Tuition Centre Name", "Subject",
"Rating" };
// array for options
std::string * optionsmain = new std::string [9]{ "Insert", "Display", "Search", "Sort",
"Modify", "Delete", "Reset", "Report",
"Exit" };
// array for insert options
std::string * optionsinsert = new std::string[3]{ "Insert (End)", "Insert (Sort)", "Back"};
// array for display options
std::string * optiondisplay = new std::string[3]{ "Display Table (Normal/Ascending Order)", "Display Table (Descending Order)", "Back" };
// array for search options
std::string * optionsearch = new std::string[2]{ "Search (Specific Value)", "Back" };
// array for sort options
std::string * optionsort = new std::string[5]{ "Sort (ID)", "Sort (Location)", "Sort (Hourly Rate)", "Sort (Rating)", "Back" };
// array for modify options
std::string * optionmodify = new std::string[2]{ "Modify (Specific Data)", "Back" };
// array for data types of modify option
std::string* modifytypes = new std::string[11]{ "Name", "Date Joined", "Date Terminated", "Hourly Rate (RM)",
"Phone", "Address", "Tuition Centre Code", "Tuition Centre Name", "Subject",
"Rating", "Back" };
// array for delete options
std::string * optiondelete = new std::string[3]{ "Delete (Row)", "Delete (All)", "Back" };
// array for true false option
std::string* truefalseoption = new std::string[2]{ "Yes", "No" };
// array for asc/desc option
std::string* ascdescoption = new std::string[2]{ "Ascending Order", "Descending Order" };
// vaiables for holding the values to form the table
int idL;
int nameL;
int datejL;
int datetL;
int rateL;
int phoneL;
int addressL;
int tccodeL;
int tcnameL;
int subjectL;
int ratingL;
// to identify which type of the user you are
int role = NULL;
struct tms {
tms* id;
tms* prev;
tms* next;
std::string name;
std::string dateJ;
std::string dateT;
double hourlyrate;
std::string phone;
std::string address;
int tccode;
std::string tcname;
std::string subject;
int rating;
}*head, *tail, *temp, *sorthead, *sorttail, *sorttemp, *reporthead, *reporttail, *reporttemp, *holdhead, *holdtail, *holdtemp;
/* function */
// assign global variable value by address
// assign role value
void assignrole(int input);
// all at once: assigning the global variable total char length all at once
void globes(int idN, int nameN, int datejN, int datetN, int rateN, int phoneN, int addressN, int tccodeN, int tcnameN, int subjectN, int ratingN);
// situational: assigning the global variable total char length based on the situation
void globe(int type, int input);
// input validation
// integer only
int intValidate(std::string input);
// double only
int doubleValidate(std::string input);
// receiving inputs and perform input validation
int inputValidation(int optionsnum);
// date format validation
// function expects the string in format yyyy/mm/dd:
bool extractDate(const std::string& s, int& y, int& m, int& d);
// validate the legitimacy of the date value
bool legitDate(std::string inputdate, std::string comparingdate);
// get the current date value
std::string currentDate();
// count the total days of the date format based on the time given
int diffDays(std::string inputdate, std::string comparingdate);
// perform the date validation on deletion requirement based on the address/ID given
bool checkDatesDiff(std::string addressSTR);
// space validation, allowing only one space for inserting NULL
int spaceValidate(std::string input);
// split the string specifically
void tokenize(std::string const& str, const char delim, std::vector<std::string>& out);
// call out a specific value of the array(pointer form)
std::string arrayOption(std::string* arr, int index);
// count the number of char within the data of the list, and find the highest value
bool totalChar();
// table lines: horizontal
void horizontalLine();
// table lines: titles
void titleLine();
// table lines: data
void dataLine();
// reversed table lines: data
void reversedDataLine();
// sorted table lines: data
void sortedDataLine();
// report table lines: data
void reportDataLine();
// display table
void displayTable();
// display table in reverse order
void displayReverseTable();
// display sorted table
void displaySortedTable();
// display report table
void displayReportTable();
// display specific table data only
void displayRow(tms * address);
// showing available options
void displayOption();
// assign and display option value for space alignment
// P.S: the arrlength will be needed to manually assign if the array is a pointer form instead of normal one since it can't be used by the macro arrayLength() to calculate the total length of the array
// showing available action within option
void displayAction(std::string* arr, int arrlength);
// verify role
void verifyrole();
// create new node
tms* createnewnode(std::string name, std::string datej, std::string datet, double hourlyrate, std::string phone, std::string address, int tccode, std::string tcname, std::string subject, int rating);
// count total nodes within the list
int totalNodes();
// insertions
// insert last
void insertLast(std::string name, std::string datej, std::string datet, double hourlyrate, std::string phone, std::string address, int tccode, std::string tcname, std::string subject, int rating);
// insert sort
void insertSort(std::string name, std::string datej, std::string datet, double hourlyrate, std::string phone, std::string address, int tccode, std::string tcname, std::string subject, int rating);
// insert into sorted list: ID
void sortedlistID(int order);
// insert into sorted list: Location
void sortedlistLocation(int order);
// insert into sorted list: Rating
void sortedlistRating(int order, tms* listtype);
// insert into sorted list: Hourly Rate
void sortedlistHourly(int order);
// search specific row based on the data
bool searchRow(int type, std::string value);
/* perform option function based on the selected option */
// main option to perform selected action
void mainOption(int option);
// insert option to perform selected action
void insertOption(int option);
// display table option to perform selected action
void displayTBLOption(int option);
// search option to perform selected action
void searchOption(int option);
// sort option to perform selected action
void sortOption(int option);
// sort option by specific data in ascending or descending order, based on the specific option
void sortData(int type, int order);
// modify option to perform selected action
void modifyOption(int option);
// delete option to perform selected action
void deleteOption(int option);
// modify
// modify specific value
void modifySpecific(std::string addressSTR);
// modify process based on the input types
bool modifyData(int type, std::string value, tms * address);
// delete specific row
void deleteRow(std::string addressSTR, tms* listtype);
// delete all
void deleteAll(tms* listtype);
// generate report
void generateReport();
// verify deletion
bool confirmDel();
// exit the system
void exitSystem();
/* function algorithms */
void assignrole(int input) {
int* address;
address = &role;
*address = input;
}
void globes(int idN, int nameN, int datejN, int datetN, int rateN, int phoneN, int addressN, int tccodeN, int tcnameN, int subjectN, int ratingN) {
int* address;
address = &idL;
*address = idN;
address = &nameL;
*address = nameN;
address = &datejL;
*address = datejN;
address = &datetL;
*address = datetN;
address = &rateL;
*address = rateN;
address = &phoneL;
*address = phoneN;
address = &addressL;
*address = addressN;
address = &tccodeL;
*address = tccodeN;
address = &tcnameL;
*address = tcnameN;
address = &subjectL;
*address = subjectN;
address = &ratingL;
*address = ratingN;
}
void globe(int type, int input) {
int* address;
switch (type) {
case 0:
address = &idL;
*address = input;
break;
case 1:
address = &nameL;
*address = input;
break;
case 2:
address = &datejL;
*address = input;
break;
case 3:
address = &datetL;
*address = input;
break;
case 4:
address = &rateL;
*address = input;
break;
case 5:
address = &phoneL;
*address = input;
break;
case 6:
address = &addressL;
*address = input;
break;
case 7:
address = &tccodeL;
*address = input;
break;
case 8:
address = &tcnameL;
*address = input;
break;
case 9:
address = &subjectL;
*address = input;
break;
case 10:
address = &ratingL;
*address = input;
break;
}
}
int intValidate(std::string input) {
// check whether there are any character other than integer exist or not
int i = 0;
int character = 0;
while (input[i])
{
if (isalpha(input[i])) {
// count the total number of alphabet character within the input
character++;
}
if (ispunct(input[i])) {
// count the total number of symbol character within the input
character++;
}
if (isspace(input[i])) {
// count the total number of space within the input
character++;
}
i++;
}
return character;
}
int doubleValidate(std::string input) {
// check whether there are any character other than integer exist or not
int i = 0;
int character = 0;
int numeric = 0;
int dot = 0;
std::string searchPunct = ",-;:'\"()?!#%&+/<=>@[]^_`{|}~";
std::string searchDouble = ".";
while (input[i])
{
if (isdigit(input[i])) {
// count the total number of numeric within the input
numeric++;
}
if (isalpha(input[i])) {
// count the total number of alphabet character within the input
character++;
}
// count the total number of symbol character except "." within the input
static const std::string searchPunct = ",-;:'\"()?!#%&+/<=>@[]^_`{|}~";
if (searchPunct.find(input[i]) != std::string::npos) {
character++;
}
// count the total number of dot character within the input
static const std::string searchDouble = ".";;
if (searchDouble.find(input[i]) != std::string::npos) {
dot++;
}
if (isspace(input[i])) {
// count the total number of space within the input
character++;
}
i++;
}
// if dot is more than one then add it into character
if (dot > 1) {
character = character + dot;
}
// if dot is one and while numeric is 0 or less than 2, means the input is only a dot, and we can't allow that
if ((dot == 1) && ((numeric == 0) || (numeric < 2))) {
character = character + dot;
}
return character;
}
int inputValidation(int optionsnum) {
std::string input;
bool validate = false;
int option = NULL;
int character = NULL;
while (validate == false) {
// validate whether the input is numeric or not
std::getline(std::cin, input);
// check whether there are any character other than input exist or not
character = intValidate(input);
// if its more than 0 then go in to the loop
while (character > 0) {
// show the message if the input is invalid
character = 0;
std::cout << "System Notice: Invalid input, please try again." << std::endl;
validate = false;
std::cout << "User Input: ";
// validate whether the input is numeric or not
std::getline(std::cin, input);
// check whether there are any character other than input exist or not
character = intValidate(input);
}
if (character == 0) {
// object from the class stringstream
std::stringstream geek(input);
// stream it to the integer
geek >> option;
if ((option < (optionsnum + 1)) && (option != 0) && (option > 0)) {
validate = true;
return option;
}
else {
validate = false;
std::cout << "System Notice: There is only " << numberenglish[(optionsnum - 1)] << " options available, please try again." << std::endl;
std::cout << "User Input: ";
}
}
}
}
bool extractDate(const std::string& s, int& y, int& m, int& d) {
std::istringstream is(s);
char delimiter;
if (is >> y >> delimiter >> m >> delimiter >> d) {
struct tm t = { 0 };
t.tm_year = y - 1900;
t.tm_mon = m - 1;
t.tm_mday = d;
t.tm_isdst = -1;
// normalize:
time_t when = mktime(&t);
const struct tm* norm = localtime(&when);
// the actual date would be:
// m = norm->tm_mon + 1;
// d = norm->tm_mday;
// y = norm->tm_year;
// e.g. 29/02/2013 would become 01/03/2013
// validate (is the normalized date still the same?):
return (norm->tm_year == y - 1900 &&
norm->tm_mon == m - 1 &&
norm->tm_mday == d);
}
return false;
}
bool legitDate(std::string inputdate, std::string comparingdate) {
std::string comparing;
int n = 1;
int tempM = NULL;
int inputY = 0;
int inputM = 0;
int inputD = 0;
int y = 0;
int m = 0;
int d = 0;
int differTotal = 0;
int intdata = NULL;
int febDay = NULL;
// get the date you want to compare
comparing = comparingdate;
// then use the comparing date to compare
// first seperate the date format specifically and assign them into specific variable
const char delim = '/';
std::vector<std::string> out;
tokenize(inputdate, delim, out);
for (auto& inputdate : out) {
// convert string into int
intdata = stoi(inputdate);
if (n == 1) {
inputY = intdata;
}
else if (n == 2) {
inputM = intdata;
}
else if (n == 3) {
inputD = intdata;
}
n++;
}
// reset the n variable back to 1 for future uses
n = 1;
std::vector<std::string> outcompare;
// first seperate the current date format specifically and assign them into specific variable
tokenize(comparing, delim, outcompare);
for (auto& comparing : outcompare) {
// convert string into int
intdata = stoi(comparing);
if (n == 1) {
y = intdata;
}
else if (n == 2) {
m = intdata;
}
else if (n == 3) {
d = intdata;
}
n++;
}
// reset the n variable back to 1 just in case
n = 1;
// perform calculation and comparison now
// before perform the calculation we will check whether its leap year or not based on the current date
if (y % 4 == 0) {
febDay = 29;
}
else {
febDay = 28;
}
if (y >= inputY) {
// first we calculate the differences of year
y = y - inputY;
// then we compare which of the month value is bigger, then calculate it if possible
if (m >= inputM) {
// assign the comparing month into temporary month before calculation for future uses
tempM = m;
m = m - inputM;
// finally we compare the days of the dateformat to calculate
if (d >= inputD) {
d = d - inputD;
// even if its more than a day than the comparing date, its legitimate
if (d >= 0) {
return true;
}
// if its zero, then its unacceptable
else {
return false;
}
}
else {
// check the value of the month is possible to countinue the calculation or not
if (m > 0) {
m = m - 1;
// if the current month is february then assign the specific days into it
if (tempM == 2) {
d = ((d + febDay) - inputD);
}
else if ((tempM == 1) || (tempM == 3) || (tempM == 5) || (tempM == 7) || (tempM == 8) || (tempM == 10) || (tempM == 12)) {
d = ((d + 31) - inputD);
}
else if ((tempM == 4) || (tempM == 6) || (tempM == 9) || (tempM == 11)) {
d = ((d + 30) - inputD);
}
// even if its more than a day than the comparing date, its legitimate
if (d >= 0) {
return true;
}
// if its zero, then its unacceptable
else {
return false;
}
}
else {
// if not then return false already since the input date format is larger than the comparing date
return false;
}
}
}
else {
// check the value of year is possible to continue the calculation or not
if (y > 0) {
y = y - 1;
m = ((m + 12) - inputM);
// this is where we 100% confirmed the comparing date format is bigger than the input date format due to the capability of adding another 12 months to perform calculation, so we straight away return true instead
return true;
}
else {
// if not then return false already since the input date format is larger than the comparing date
return false;
}
}
}
else {
// since from the year we already know which date is actually bigger so we straight return false to notify the input date is larger than comparing date
return false;
}
}
std::string currentDate() {
std::string now;
// getting the current time
std::time_t rawtime;
std::tm* timeinfo;
char buffer[80];
std::time(&rawtime);
timeinfo = std::localtime(&rawtime);
std::strftime(buffer, sizeof(buffer), "%Y/%m/%d", timeinfo);
std::string str(buffer);
now = buffer;
return now;
}
int diffDays(std::string inputdate, std::string comparingdate) {
int total = 0;
std::string comparing;
int n = 1;
bool check = false;
int tempM = NULL;
int tempY = NULL;
int calcY = NULL;
int used = 0;
int inputY = 0;
int inputM = 0;
int inputD = 0;
int y = 0;
int m = 0;
int d = 0;
int differTotal = 0;
int intdata = NULL;
int febDay = NULL;
int yearlyDay = NULL;
// get the date you want to compare
comparing = comparingdate;
// then use the comparing date to compare
// first seperate the date format specifically and assign them into specific variable
const char delim = '/';
std::vector<std::string> out;
tokenize(inputdate, delim, out);
for (auto& inputdate : out) {
// convert string into int
intdata = stoi(inputdate);
if (n == 1) {
inputY = intdata;
}
else if (n == 2) {
inputM = intdata;
}
else if (n == 3) {
inputD = intdata;
}
n++;
}
// reset the n variable back to 1 for future uses
n = 1;
std::vector<std::string> outcompare;
// first seperate the current date format specifically and assign them into specific variable
tokenize(comparing, delim, outcompare);
for (auto& comparing : outcompare) {
// convert string into int
intdata = stoi(comparing);
if (n == 1) {
y = intdata;
}
else if (n == 2) {
m = intdata;
}
else if (n == 3) {
d = intdata;
}
n++;
}
// reset the n variable back to 1 just in case
n = 1;
// perform calculation and comparison now
// before perform the calculation we will check whether its leap year or not based on the current date
if (y % 4 == 0) {
febDay = 29;
yearlyDay = 366;
}
else {
febDay = 28;
yearlyDay = 365;
}
tempY = y;
if (y >= inputY) {
// first we calculate the differences of year
y = y - inputY;
// then we compare which of the month value is bigger, then calculate it if possible
if (m >= inputM) {
// assign the comparing month into temporary month before calculation for future uses
tempM = m;
m = m - inputM;
// finally we compare the days of the dateformat to calculate
if (d >= inputD) {
d = d - inputD;
// even if its more than a day than the comparing date, its legitimate
if ((d > 0) || (y > 0) || (m > 0)) {
// start to count the total days of between the two date format
check = true;
}
// if its zero, then its unacceptable
else {
return false;
}
}
else {
// check the value of the month is possible to countinue the calculation or not
// if m is 0 while y is not, then we can substract and add 12 on m
if ((y != 0) & (m == 0)) {
y = y - 1;
m = m + 12;
}
if (m > 0) {
m = m - 1;
// if the current month is february then assign the specific days into it
if (tempM == 2) {
d = ((d + febDay) - inputD);
}
else if ((tempM == 1) || (tempM == 3) || (tempM == 5) || (tempM == 7) || (tempM == 8) || (tempM == 10) || (tempM == 12)) {
d = ((d + 31) - inputD);
}
else if ((tempM == 4) || (tempM == 6) || (tempM == 9) || (tempM == 11)) {
d = ((d + 30) - inputD);
}
// even if its more than a day than the comparing date, its legitimate
if ((d > 0) || (y > 0) || (m > 0)) {
check = true;
}
// if its zero, then its unacceptable
else {
return false;
}
}
else {
// if not then return false already since the input date format is larger than the comparing date
return false;
}
}
}
else {
// check the value of year is possible to continue the calculation or not
if (y > 0) {
y = y - 1;
tempM = m;
m = ((m + 12) - inputM);
// finally we compare the days of the dateformat to calculate
if (d >= inputD) {
d = d - inputD;
// even if its more than a day than the comparing date, its legitimate
if ((d > 0) || (y > 0) || (m > 0)) {
// start to count the total days of between the two date format
check = true;
}
// if its zero, then its unacceptable
else {
return false;
}
}
else {
// check the value of the month is possible to countinue the calculation or not
if (m > 0) {
m = m - 1;
// if the current month is february then assign the specific days into it
if (tempM == 2) {
d = ((d + febDay) - inputD);
}
else if ((tempM == 1) || (tempM == 3) || (tempM == 5) || (tempM == 7) || (tempM == 8) || (tempM == 10) || (tempM == 12)) {
d = ((d + 31) - inputD);
}
else if ((tempM == 4) || (tempM == 6) || (tempM == 9) || (tempM == 11)) {
d = ((d + 30) - inputD);
}
// even if its more than a day than the comparing date, its legitimate
if ((d > 0) || (y > 0) || (m > 0)) {
check = true;
}
// if its zero, then its unacceptable
else {
return false;
}
}
else {
// if not then return false already since the input date format is larger than the comparing date
return false;
}
}
}
else {
// if not then return false already since the input date format is larger than the comparing date
return false;
}
}
}
else {
// since from the year we already know which date is actually bigger so we straight return false to notify the input date is larger than comparing date
return false;
}
// if once we know the calculation can be done then we start the calculation
if (check != false) {
// count the total number of the days
// if after calculation the year is only 1 or 0 then calculate it straightforwardly
if ((y == 1) || (y == 0)) {
total = total + ((y * yearlyDay) + (d));
// if after calculation the number of months is not equal 0 then
if (m != 0) {
// in descending order for accuracy, e.g: 10, 9, 8, 7, 6 month
for (int i = m; i > 0; i--) {
tempM--;
if ((tempM == 0) && (((tempY - inputY) - used) > 0)) {
tempM = tempM + 12;
used++;
}
// add the specific total days based on the specific month
if (tempM == 2) {
total = total + febDay;
}
else if ((tempM == 1) || (tempM == 3) || (tempM == 5) || (tempM == 7) || (tempM == 8) || (tempM == 10) || (tempM == 12)) {
total = total + 31;
}
else if ((tempM == 4) || (tempM == 6) || (tempM == 9) || (tempM == 11)) {
total = total + 30;
}
}
}
}
// else if after calculation the year is more than 1, means we need to calculate it accordingly, by checking whether its leap year or not
else if (y > 1) {
// first we add the current total with the day we have
total = total + d;
// assign the tempY value to calcY
calcY = tempY;
// then we put into a while loop by constantly check the leap year and add it specifically
if (y != 0) {
// in descending order for accuracy, e.g: 2020, 2019, 2018 year, etc
for (int i = y; i >= 0; i--) {
tempY = tempY - 1;
// before perform the calculation we will check whether its leap year or not based on the current date
if (tempY % 4 == 0) {
febDay = 29;
yearlyDay = 366;
}
else {
febDay = 28;
yearlyDay = 365;
}
// if after calculation the number of months is not equal 0 then
if (m != 0) {
// in descending order for accuracy, e.g: 10, 9, 8, 7, 6 month
for (int i = m; i > 0; i--) {
tempM--;
if ((tempM == 0) && (((calcY - inputY) - used) > 0)) {
tempM = tempM + 12;
used++;
}
// add the specific total days based on the specific month
if (tempM == 2) {
total = total + febDay;
}
else if ((tempM == 1) || (tempM == 3) || (tempM == 5) || (tempM == 7) || (tempM == 8) || (tempM == 10) || (tempM == 12)) {
total = total + 31;
}
else if ((tempM == 4) || (tempM == 6) || (tempM == 9) || (tempM == 11)) {
total = total + 30;
}
}
}
// make the m as 12 (count from December descendingly) since we've count the remaining months and proceed to the remaining year's month
m = 12;
}
}
}
}
return total;
}
bool checkDatesDiff(std::string addressSTR) {
// this deletion function that required us to check the date requirement is based on the main list: head
// so we call head into the temp for calling the date value (date joined and terminated)
temp = head;
std::string tempSTR;
int datediff = NULL;
bool found = false;
bool legit = false;
// convert address into string
std::ostringstream get_the_address;
while (temp != NULL) {
// convert addresses into string
get_the_address << temp;
tempSTR = get_the_address.str();
// break when we found the exact ID
// no checking of the ID whether exist within the list required as we did that in the previous function