-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpseudo.txt
More file actions
1545 lines (1232 loc) · 49.4 KB
/
pseudo.txt
File metadata and controls
1545 lines (1232 loc) · 49.4 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
//account.c (10 functions)
//The Welcome Page for Both Users and Admin
INCLUDE account.h as header file
FUNCTION welcomePage()
DECLARE option as Integer
DECLARE user as Account Struct
DOWHILE option = 0
DISPLAY 'Welcome to Goldfish Task Management System!'
DISPLAY '[ 1 ] - 'Login
DISPLAY '[ 2 ] - Register'
DISPLAY 'Please Enter Your Choice Number:'
READ option
CASE OF option
1: CALL FUNCTION loginUser()
2: CALL FUNCTION registration()
default: option = 0
break
ENDCASE
ENDDO
ENDFUNCTION
-----------------------------------------------------------------------------------------------
//Registration Page for Both User and Admin
FUNCTION registration()
DECLARE user as Account Struct
DECLARE fileAppender as file pointer
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE checkFileExistence(fileName, fileHandling_method, createFileIfNotExist) as FUNCTION
DECLARE register_username(user.username) as FUNCTION
DECLARE register_password(user.password) as FUNCTION
DECLARE register_name(user.name) as FUNCTION
DECLARE register_contactNum(user.contactNum) as FUNCTION
DECLARE register_dateOfBirth(&user.dateOfBirth) as FUNCTION
DECLARE register_email(user.email) as FUNCTION
fileAppender = CALL FUNCTION checkFileExistence("user.txt", "a", 1)
CALL FUNCTION register_username(user.username)
CALL FUNCTION register_password(user.password)
CALL FUNCTION register_name(user.name)
CALL FUNCTION register_contactNum(user.contactNum)
CALL FUNCTION register_dateOfBirth(&user.dateOfBirth)
CALL FUNCTION register_email(user.email)
DISPLAY 'Confirming details...'
DISPLAY 'Welcome,' user.name
write user into user.txt file with the size of Account using fileAppender
close fileAppender
DISPLAY 'Registration Successful!'
ENDFUNCTION
---------------------------------------------------------------------------------------
//Function To Register the Username
DECLARE usernameTarget as Character pointer
FUNCTION register_username(usernameTarget)
DECLARE userFileReader as file pointer
DECLARE validated as Integer
DECLARE match as Integer
DECLARE username as Character Array with length of 21
DECLARE usernameCopy as Character Array with length of 21
DECLARE existingUser as Account Struct
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE checkFileExistence(fileName, fileHandling_method, createFileIfNotExist)
set validated to FALSE
set match to FALSE
DOWHILE (validated = FALSE)
flush the input stream
DISPLAY 'Please Enter Your New Username:'
READ username
copy character string from usernameCopy to username
userFileReader = CALL FUNCTION checkFileExistence("user.txt", "r", 0)
WHILE (read the existingUser from the file with the size of Account using userFileReader)
covert existingUser.username to lowercase
IF (existingUser.username is not same as usernameCopy) THEN
DISPLAY 'Username is occupied! Please use Another Username.'
match = true
break
ENDIF
ENDWHILE
close the userFileReader
IF (match = TRUE) THEN
validated = TRUE
copy character string from username to usernameTarget
ENDIF
ENDDO
ENDFUNCTION
-------------------------------------------------------------------------------------------
//Function To Register User Password
DELCARE passwordTarget as Character pointer
FUNCTION register_password(passwordTarget)
DELCARE password as Character Array with length of 21
DELCARE confirmPassword as Character Array with length of 21
WHILE TRUE
flush the input stream
DISPLAY 'Please Enter Your New Password (8-20 characters):'
READ password
IF (length of password <8 OR length of password >20) THEN
DISPLAY 'Invalid Password! Please Ensure Your New Password have 8-20 Characters'
continue
ENDIF
flush the input stream
DISPLAY 'Please Enter Your New Password Again:'
READ confirmPassword
IF confirmPassword not equal to password THEN
DISPLAY 'Invalid Input! Please Ensure That You Have Entered the Same Password!'
continue
ENDIF
DISPLAY 'Correct Password Format!\nCongrats! Your New Password has been Verified!'
copy character string from password to passwordTarget
ENDWHILE
ENDFUNCTION
---------------------------------------------------------------------------------------------------------
//Function To Register User's Name
DELCARE nameTarget as Character pointer
FUNCTION register_name(nameTarget)
DELCARE name as Character Array with length of 256
flush the input stream
DISPLAY 'Please Enter Your Name:'
READ name
copy character string from name to nameTarget
ENDFUNCTION
-----------------------------------------------------------
//Function To Register User's Contact Number
DELCARE contactNumTarget as Character pointer
FUNCTION register_contactNum(contactNumTarget)
DELCARE contactNum as Character Array with length of 11
WHILE TRUE
flush the input stream
DISPLAY 'Please Enter Your Contact Number (without'-'): 60'
READ contactNum
IF contactNum is a number THEN
IF (contactNum[0] = '1' AND (contactNum[1] != '1' AND (length of contactNum == 9) OR contactNum[1] == '1' AND (length of contactNum == 10)) THEN
DISPLAY 'Correct Phone Number Format! Congrats! Your Phone Number has been Verified!'
copy character string from contactNum to contactNumTarget
break
ENDIF
DISPLAY 'Invalid Phone Number! Please Ensure Your Registered Phone Number have correct length!'
continue
ELSE
DISPLAY 'Invalid Phone Number! Please Ensure Your Registered Phone Number contains only number!'
continue
ENDIF
ENDWHILE
ENDFUNCTION
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function To Register User's Date of Birth
DECLARE dateOfBirthTarget as Date Struct
FUNCTION register_dateOfBirth(dateOfBirthTarget)
DISPLAY 'Please Enter Your Date of Birth:'
CALL FUNCTION dateValidation(dateOfBirthTarget)
DISPLAY 'Congrats! Your Date of Birth has been Verified!'
ENDFUNCTION
--------------------------------------------------------------------------------------------
//Function To Register User's Email Address
DECLARE emailTarget as Character pointer
FUNCTION register_email(emailTarget)
DECLARE email as Character Array with length of 321
WHILE TRUE
flush the input stream
DISPLAY 'Please Enter Your Email:'
READ email
IF email contains '@' AND '.com' THEN
DISPLAY 'Congrats! Your Email has been Verified!'
copy character string from email to emailTarget
break
ENDIF
DISPLAY 'Wrong Email Format! Please Try Again!'
continue
ENDWHILE
ENDFUNCTION
--------------------------------------------------------------------------------------------
//Login Page for Both User and Admin
FUNCTION loginUser()
DECLARE found as Integer
DECLARE password as Character Array with length of 256
DECLARE username as Character Array with length of 256
DECLARE user as Account Struct
DECLARE userFileReader as file pointer
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE checkFileExistence(fileName, fileHandling_method, createFileIfNotExist)
set found to FALSE
DISPLAY 'Login Page'
DISPLAY 'Please Enter Your Login Credentials Below:'
DOWHILE (found = FALSE)
userFileReader = CALL FUNCTION checkFileExistence("user.txt", "r", 0)
flush the input stream
DISPLAY 'Username:'
READ username
covert username to lowercase
flush the input stream
DISPLAY 'Password:'
READ password
WHILE (read the user from file with the size of Account using userFileReader) ##
covert existingUser.username to lowercase
IF ((user.username is same as username) AND (user.password is same as password)) THEN
DISPLAY 'Welcome back!', user.name
close userFileReader
found = TRUE
return user
ENDIF
ENDWHILE
IF (found = FALSE) THEN
DISPLAY 'Incorrect Login DetailS. Please enter the correct credentials!'
ENDIF
ENDWHILE
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Change Password ############################
DELCARE username as Character pointer
DELCARE password as Character pointer
FUNCTION changePassword(username, password)
DECLARE user as Account Struct
DECLARE confirmPassword as Character array with length of 256
DECLARE newPassword as Character pointer
DECLARE userFileReader as file pointer
DECLARE userFileWriter as file pointer
DECLARE passwordCorrect as Integer
DECLARE register_password as Function
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE checkFileExistence(fileName, fileHandling_method, createFileIfNotExist)
userFileReader = CALL FUNCTION checkFileExistence("user.txt", "r", 0)
opem temp_user.txt file in write mode using userFileWriter
set Found as FALSE
DOWHILE (passwordCorrect = FALSE)
flush the input stream
DISPLAY 'Please Enter Your Current Password:'
READ confirmPassword
IF (confirmPassword is same as password) THEN
passwordCorrect = TRUE
break
ELSE
DISPLAY 'Incorrect Password! Please Try Again!'
continue
ENDIF
ENDDO
flush the input stream
CALL FUNCTION register_password(newPassword)
WHILE (read user from file with the size of Account using userFileReader)
IF (user.username is not same as username) THEN
copy character string from newPassword to user.password
ENDIF
write user into the file with the size of Account using userFileWriter
ENDWHILE
close userFileReader
close userFileWriter
DISPLAY 'Done!'
remove user.txt
rename the temp_user.txt to user.txt
ENDFUNCTION
-----------------------------------------------------------------------------
//admin.c (4 functions)
//Function of Admin Main Page
INCLUDE admin.h as header file
FUNCTION admPage()
DECLARE continueAdminChoice as Integer
DECLARE admUsername as Character Array
DECLARE maxChoice as Integer
DECLARE minChoice as Integer
DECLARE getChoiceNum(maxChoice, minChoice) as Function
DECLARE adminChoice as Integer
set continueAdminChoice as TRUE
DOWHILE (continueAdminChoice = TRUE)
DISPLAY '======================='
DISPLAY 'Welcome to Admin Page!'
DISPLAY '======================='
DISPLAY '[ 1 ] - Recover User's Account'
DISPLAY '[ 2 ] - Update Admin Details'
DISPLAY '[ 3 ] - Change Admin Account Password'
DISPLAY '[ 0 ] - Back to the Main Page'
CALL getChoiceNum(3, 0)
CASE OF adminChoice
1:
CALL FUNCTION recoverUserAcct()
break
2: CALL FUNCTION updateAdmDetail(admUsername)
break
3: CALL FUNCTION changePassword()
break
0: continueAdminChoice = FALSE
break
ENDCASE
ENDWHILE
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Recover User Account In the Case of Forgot Password
FUNCTION recoverUserAcct()
DECLARE searchKey as Character Array with length of 21
DECLARE searchSource as Character Array with length of 21
DECLARE lastSixDigit as Character Array with length of 7
DECLARE acct as Account Struct
DECLARE userFileReader as file pointer
DECLARE userFileWriter as file pointer
DECLARE found as Integer
DECLARE newPass as Character Array with length of 50
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE checkFileExistence(fileName, fileHandling_method, createFileIfNotExist)
set found as FALSE
flush the input stream
DISPLAY 'Please Enter the Account Username that You Would Like to Recover:'
READ searchKey
convert searchKey to lowercase
userFileReader = CALL FUNCTION checkFileExistence("user.txt", "r", 0)
open temp_user.txt file in write mode using userFileWriter
WHILE (read acct in the size of Account using userFileReader)
copy character string from acct.username to searchSource
convert searchSource to lowercase
IF searchSource is same as searchKey
found = TRUE
DISPLAY 'Recovering account...'
lastSixDigits = last six characters of acct.contactNum
copy character string from acct.username to newPass
concatenates newPass and lastSixDigits
DISPLAY 'Congratulations! The Account Has Been Recovered!'
DISPLAY 'The New Password of is', newPass
ENDIF
write acct into the file in the size of Account using userFileWriter
ENDWHILE
close userFileReader
close userFileWriter
DISPLAY 'Done!'
remove user.txt
rename temp_user.txt to user.txt
IF (found = FALSE)
DISPLAY ('No Username Found. Please Ensure Your Entered A Correct Username.')
ENDIF
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Update Admin Details
DECLARE username as Character pointer
FUNCTION updateAdmDetail(char *username)
DECLARE acct as Account
DECLARE userFileReader as file pointer
DECLARE userFileWriter as file pointer
DECLARE displayAdmDetail as Function
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE checkFileExistence(fileName, fileHandling_method, createFileIfNotExist)
userFileReader = CALL FUNCTION checkFileExistence("user.txt", "r", 0)
open temp_user.txt in write mode using userFileWriter
WHILE (read acct from the file with the size of Account using userFileReader)
CALL FUNCTION displayAdmDetail(acct)
ENDWHILE
write acct into the file with the size of Account using userFileWriter
close userFileReader
close userFileWriter
DISPLAY 'Done!'
remove user.txt
rename temp_user.txt to user.txt
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Display Admin's Current Details
FUNCTION displayAdmDetail(Account acct)
DECLARE editChoice as Integer
DISPLAY '[ 1 ]- Username', acct.username
DISPLAY '[ 2 ]- Admin Name', acct.name
DISPLAY '[ 3 ]- Contact Number', acct.contactNum
DISPLAY '[ 4 ]- Date of Birth', acct.dateOfBirth.day, acct.dateOfBirth.month, acct.dateOfBirth.year
DISPLAY '[ 5 ]- Email Address', acct.email
flush the input stream
editchoice = CALL FUNCTION getChoiceNum(5,1)
CASE OF editChoice
1:
CALL FUNCTION register_username(acct.username)
break
2: CALL FUNCTION register_name(acct.name)
break
3: CALL FUNCTION register_contactNum(acct.contactNum)
break
4: CALL FUNCTION register_dateOfBirth(acct.dateOfBirth)
break
5: CALL FUNCTION register_email(acct.email)
break
ENDCASE
ENDFUNCTION
-----------------------------------------------------------------------------
//date.c (1 function)
INCLUDE stdio.h as header file
INCLUDE stdlib.h as header file
INCLUDE string.h as header file
INCLUDE ctype.h as header file
INCLUDE date.h as header file
INCLUDE menu.h as header file
FUNCTION dateValidation(Date *dateTarget)
DECLARE dateInput as Character Array with length of 11
DECLARE dateInputCopy as Character Array with length of 11
DECLARE DELIMITER as Constant Character
DECLARE token as Character
DECLARE day as Integer
DECLARE month as Integer
DECLARE year as Integer
DECLARE printDateError() as function
set DELIMITER as '/'
WHILE TRUE
flush the input stream
DISPLAY 'Please enter the date in (DD/MM/YYYY):'
READ dateInput
copy character string from dateInput to dateInputCopy
IF (length of dateInput >= 8 AND length of dateInput <= 10) THEN
token = tokenizing dateInputCopy based on DELIMITER
IF (length of token equal to length of dateInput) THEN
DELIMITER = "-"
token = tokenizing dateInput based on DELIMITER
ENDIF
IF ( length of token == 1 OR length of token == 2 AND checkIsNumber(token) == 1) THEN
day = convert token into an Integer
token = tokenizing NULL based on DELIMITER
IF ( length of token == 1 OR length of token == 2 AND checkIsNumber(token) == 1) THEN
month = convert token into an Integer
token = tokenizing NULL based on DELIMITER
IF (length of token == 4 AND checkIsNumber(token) == 1) THEN
year = convert token into an Integer
if(year >= 1900 AND year <= 2022) THEN
if(month >= 1 AND month <= 12) THEN
if( (day >= 1 AND day <= 31)
AND (month >= 1
AND month <= 7
AND month % 2 == 1
AND month >= 8
AND month <= 12
AND month % 2 == 0)
OR (day >= 1 AND day <= 30)
AND (month==4
OR month ==6
OR month == 9
OR month == 11)
OR (day >= 1
AND day <= 28
AND month == 2)
OR (day == 29
AND month == 2
AND year % 400 == 0)
OR (year %4 == 0
AND year %100 != 0)
dateTarget.day = day
dateTarget.month = month
dateTarget.year = year
break
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
DISPLAY 'Invalid Date Entry. Please Try Again.'
continue
ENDIF
ENDWHILE
ENDFUNCTION
-----------------------------------------------------------------------------
//file.c (1 function)
//File Handling Function to Check the Existence of the File
INCLUDE file.h header file
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE filePointer as file pointer
DECLARE filePointer1 as file pointer
DECLARE choice as character
FUNCTION checkFileExistence (fileName, fileHandling_method, createFileIfNotExist)
WHILE TRUE
open fileName in fileHandling_method using filePointer
IF (filePointer == NULL) THEN
IF (createFileIfNotExist = TRUE) THEN
open fileName in write mode using filePointer1
close (filePointer1)
continue
DISPLAY 'Target file does not exist.'
DISPLAY 'Enter any key to continue after relocating the file.'
DISPLAY '[X] - To Exit'
read choice
convert choice to lowercase
IF (length of choice == 2 AND choice == 'x') THEN
exit the program
break
ELSE
continue
ENDIF
ELSE
return filePointer
ENDIF
ENDIF
ENDWHILE
ENDFUNCTION
-----------------------------------------------------------------------------
//menu.c (5 functions)
INCLUDE menu.h as header file
//Function to Display User Main Menu
FUNCTION user_menu()
DISPLAY '[ 1 ] - Add New Task'
DISPLAY '[ 2 ] - Sort and View Tasks'
DISPLAY '[ 3 ] - View All Tasks'
DISPLAY '[ 4 ] - Update Task'
DISPLAY '[ 5 ] - Delete Task'
DISPLAY '[ 6 ] - Search Task'
DISPLAY '[ 7 ] - Change Password'
DISPLAY '[ X ] - Exit'
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Display Admin Main Menu
FUNCTION admin_menu()
DISPLAY '[ 1 ] - Recover User's Account'
DISPLAY '[ 2 ] - Search User Tasks'
DISPLAY '[ 3 ] - Update Admin Details'
DISPLAY '[ 4 ] - Change Admin Password'
DISPLAY '[ X ] - Exit'
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Prompt User for the Menu Choice Number Input
DECLARE maxChoice as integer
DECLARE minChoice as integer
FUNCTION getChoiceNum(maxChoice, minChoice)
DECLARE userInput as character array with length of 256
DECLARE userInput_length as integer
DECLARE choice as integer
DECLARE userExitInput as character array with length of 256
DECLARE userExitInput_length as integer
WHILE TRUE
DISPLAY 'Select a choice:'
READ userInput
IF (userInput is not a number) THEN
choice = convert userInput into integer
IF (choice >= minChoice AND choice <= maxChoice) THEN
return choice
ELSE
DISPLAY 'Your Choice is not in available selection range.'
continue
ENDIF
ELSE
convert userInput to lowercase
IF (userInput_length == 1 AND userInput[0] == 'x') THEN
DISPLAY 'Confirm Exit?'
DISPLAY '[ X ] - To Confirm Exit'
READ userExitInput
userExitInput_length = length of characters in userExitInput
onvert userExitInput to lowercase
IF (userExitInput_length == 1 AND userExitInput[0] == 'x') THEN
exit the program
break
ELSE
continue
ENDIF
ELSE
DISPLAY 'Is Not a Validated Number.'
continue
ENDIF
ENDIF
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Validate if Given Input is a Number ****************************NEED CHECK FOR LOOP
DECLARE target as character pointer
FUNCTION checkIsNumber(target)
DECLARE targetLength as integer
DECLARE validatedLength as integer
DECLARE i as integer
set validatedLength as FALSE
targetLength = length of characters in target
set i as FALSE
LOOP i FROM 0 To length of target STEP 1
IF (target[i] is a digit AND target[i] == 1) THEN
validatedLength = TRUE
ENDIF
NEXT i
ENDLOOP
IF (targetLength is equal to validatedLength)
return TRUE
ENDIF
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Convert the Entire User Input into Lower Case
DECLARE str as character pointer
FUNCTION toLower(str)
DECLARE i as integer
LOOP i FROM 0 To str[i] STEP 1
str[i] = convert one i into lowercase
NEXT i
ENDLOOP
ENDFUNCTION
-----------------------------------------------------------------------------
//task.c (25 functions)
//Function to Add Task
DECLARE username as character pointer
FUNCTION addTask(username)
DECLARE tasks AS Task Struct
DECLARE numberOfTasks as integer
DECLARE getChoiceNum(maxChoice,minChoice) as Function
DECLARE i as integer
DECLARE setTaskCategory(&tasks[i]) as FUNCTION
DECLARE setTaskTitle(&tasks[i]) as FUNCTION
DECLARE setTaskCategory(&tasks[i]) as FUNCTION
DECLARE setTaskDescription(&tasks[i]) as FUNCTION
DECLARE setTaskStatusCode(&tasks[i]) as FUNCTION
DECLARE setTaskPriorityCode(&tasks[i]) as FUNCTION
DECLARE setTaskDeadline(&tasks[i]) as FUNCTION
DECLARE confirmTask(username, &tasks[i]) as FUNCTION
DECLARE appendTask(username, tasks[i])as FUNCTION
DISPLAY 'Welcome to Add Task Section'
DISPLAY 'Please Enter the Number of New Tasks to Be Added:'
numberOfTasks = CALL FUNCTION getChoiceNum(10, 0)
tasks = allocate memory blocks with the same amount as the numberOfTasks of the size of Task
LOOP i FROM 0 To numberOfTasks STEP 1
copy character string from username to tasks[i].username
CALL FUNCTION setTaskCategory(&tasks[i])
CALL FUNCTION setTaskTitle(&tasks[i])
CALL FUNCTION setTaskDescription(&tasks[i])
CALL FUNCTION setTaskStatusCode(&tasks[i])
CALL FUNCTION setTaskPriorityCode(&tasks[i])
CALL FUNCTION setTaskDeadline(&tasks[i])
CALL FUNCTION confirmTask(username, &tasks[i])
CALL FUNCTION appendTask(username, tasks[i])
NEXT i
ENDLOOP
return FALSE
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Select the New Task Category
DECLARE tasks as Task Struct
FUNCTION setTaskCategory(tasks)
DECLARE categoryChoice as Integer
DISPLAY '===== Please Select the New Task Category ====='
DISPLAY '[ 1 ] - Personal'
DISPLAY '[ 2 ] - Work'
DISPLAY '[ 3 ] - Social'
DISPLAY '[ 4 ] - Create New Category'
categoryChoice = CALL FUNCTION getChoiceNum(4, 1)
CASE OF categoryChoice
1:
copy character string from "Personal" to task.category
break
2: copy character string from "Work" to task.category
break
3: copy character string from "Social" to task.category
break
4: flush the input stream
DISPLAY 'Please Enter Your New Task Category:'
READ tasks.category
break
ENDCASE
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Set the New Task Title
DECLARE task as Task Struct
FUNCTION setTaskTitle(task)
flush the input stream
DISPLAY 'Please Enter the New Task Title:'
READ task.title
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Set the New Task Description
DECLARE task as Task Struct
FUNCTION setTaskDescription(task)
flush the input stream
DISPLAY 'Please Enter the New Task Description (Max 1000 Characters) :'
READ task.description
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Set the New Task Status Code
DECLARE task as Task Struct
FUNCTION setTaskStatusCode(task)
DECLARE maxChoice as Integer
DECLARE minChoice as Integer
DECLARE getChoiceNum(maxChoice, minChoice) as Function
DISPLAY '===== Please Select the New Task Status ====='
DISPLAY '[ 1 ] - Not Started'
DISPLAY '[ 2 ] - In Progress'
DISPLAY '[ 3 ] - Done'
DISPLAY '[ 4 ] - Canceled'
task.status_code = CALL FUNCTION getChoiceNum(4, 1)
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Set the New Task Priority Code
DECLARE task as Task Struct
FUNCTION setTaskPriorityCode(task)
DISPLAY '===== Please Select the New Task Priority ====='
DISPLAY '[ 1 ] - Low'
DISPLAY '[ 2 ] - Normal'
DISPLAY '[ 3 ] - Slightly Urgent'
DISPLAY '[ 4 ] - Urgent'
task.priority_code = CALL FUNCTION getChoiceNum(4, 1)
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Set the New Task Deadline
DECLARE task as Task Struct
FUNCTION setTaskDeadline(task)
DECLARE dateTarget as Date Struct
DECLARE dateValidation(dateTarget) as function
DISPLAY 'Please Enter the Deadline of the Task :'
CALL FUNCTION dateValidation(task.deadline)
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to create New Task Confirmation
DECLARE task as Task Struct
DECLARE username as Character pointer
FUNCTION confirmTask(username, task)
DECLARE continueLoop as integer
DECLARE displayTask(task) as function
DECLARE confirmChoice as integer
DECLARE modifyChoice as integer
set continueLoop as TRUE
DOWHILE (continueLoop = TRUE)
DISPLAY '======================================================='
DISPLAY 'Task Confirmation'
DISPLAY '======================================================='
CALL FUNCTION displayTask(task)
DISPLAY 'Confirm task details?'
DISPLAY '[ 1 ] - Confirm'
DISPLAY '[ 2 ] - Modify'
confirmChoice = CALL FUNCTION getChoiceNum(2, 1)
CASE OF confirmChoice
1:
continueLoop = FALSE
break
2:
DISPLAY 'Please Select the Task Field to be Modified:'
DISPLAY '[ 1 ] - Category'
DISPLAY '[ 2 ] - Title'
DISPLAY '[ 3 ] - Description'
DISPLAY '[ 4 ] - Status'
DISPLAY '[ 5 ] - Priority'
DISPLAY '[ 6 ] - Deadline'
DISPLAY '[ 0 ] - Back'
modifyChoice = CALL FUNCTION getChoiceNum(6, 0)
CASE OF modifyChoice
1:
CALL FUNCTION setTaskCategory(task)
break
2:
CALL FUNCTION setTaskTitle(task)
break
3:
CALL FUNCTION setTaskDescription(task)
break
4:
CALL FUNCTION setTaskStatusCode(task)
break
5:
CALL FUNCTION setTaskPriorityCode(task)
break
6:
CALL FUNCTION etTaskDeadline(task)
break
0:
continueLoop = FALSE
break
ENDCASE
ENDDO
DISPLAY 'Recording Your Task....'
ENDFUNCTION
-----------------------------------------------------------------------------
//Function to Append the New Task Added into the Database
DECLARE task as Task Struct
DECLARE username as Character pointer
FUNCTION appendTask(username, task)
DECLARE taskId as integer
DECLARE readTask as Task Struct
DECLARE taskFileAppenderPlus as file pointer
DECLARE fileName as character pointer
DECLARE fileHandling_method as character pointer
DECLARE createFileIfNotExist as integer
DECLARE checkFileExistence(fileName, fileHandling_method, createFileIfNotExist) as function
taskFileAppenderPlus = checkFileExistence("task_record.txt", "a+", 1)
WHILE (read readtask from the file with the size of Task using taskFileAppenderPlus)
IF (readTask.username is same as username) THEN
taskId = taskId + 1
ENDIF
ENDWHILE
task.taskId = taskId