In: Computer Science
Write a program that checks whether or not a date entered in by the user is valid. Display the date and say if it is valid. If it is not valid explain why.
I don't need the coding. Just help with the questions 1 and 2.
Flowchart For Date Validity
Refer to below image and i am explaining the numbering mentioned there block by block what is being done
1. We are informing user to enter a date in the format of dd/mm/yyyy and take input from user and store value in three variables named as dd,mm,yy.
2. We are checking yy valid or not by if(yy>=1900 && yy<=9999)
3.If 2 is not true we are printing month is invalid
4. Here we are checking date is between 1 to 31 and months having 31 days along with that i.e Jan, Mar,May ,july ,Aug ,Oct ,Dec
like this
if((dd>=1 && dd<=31) && (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12))
5. Here we are checking date is between 1 to 30 and months having 30 days along with that i.e April ,June ,Sept,November.
((dd>=1 && dd<=30) && (mm==4 || mm==6 || mm==9 || mm==11))
6. A special for date of february is done i.e data is between 1 to 28 and month is february or mm==2;
((dd>=1 && dd<=28) && (mm==2))
7. Checking Leap Year And If it is a leap yera then February has 29 days so check for both
(dd==29 && mm==2 && (yy%400==0 ||(yy%4==0 && yy%100!=0)))
8. If all of the 4 5 6 7 block dissatisfy then we print date is invalid.
9. If any of the block 4 5 6 7 block satisfy the condition then we print date is valid
10 . Put each last block to end .
Flowchart Ends
Q2
Boolean Expression is