iPad 7:45 anm 38%-- StudyDesk S1 2018 MAT1101 Question 3 [6 marks] Consider the
ID: 3699722 • Letter: I
Question
iPad 7:45 anm 38%-- StudyDesk S1 2018 MAT1101 Question 3 [6 marks] Consider the following algorithm yearInput a four digit year 2. if (year mod 4 -0)Divisible by 4 2.1 if (year mod 100 0Dvisible by 100 2.1.1 if (year mod 400 0) Divisible by 400 2.1.1.1 isLeapYear _TRUE; 2.1.2 Else 2.1.2.1 isLeapYear FALSE; 2.1.3End if 2.2 Else Not divisible by 100] 2.2.1 isLeapYear ? TRUE; 2.3 End if 3. Else Not divisible by 4] 3.1 isLeapYear ? FALSE 4. End if 5. Output isLeapYear a) Trace the algorithm starting with the input 1500 b) Document the changes that would need to be made to the algorithm after step 4 to output the number of days in a specific year. Make sure that you describe the changes in detail. End of ASSIGNMENT QUESTIONSExplanation / Answer
a) Tracing the algorithm if year is 1500
1. year <- 1500
2. (year mod 4 = 0) <- 1500 mod 4 = 0 , Statement is True
2.1 (year mod 100 = 0) ,<- 1500 mod 100 = 0, Statement is True
2.1.1 (year mod 400 = 0) <- 1500 mod 400 = 3 , Statement is False
2.1.2 Else
2.1.2.1 isLeapYear <- False
4 End If
5 Output isLeapYear <- False
b) Changes to print number of days in a year after step 4
4.1 if isLeapYear {isLeapYear is True}
4.1.1 numberOfDays <- 366 {Leap Year has total days as 366}
4.2 Else
4.2.1 numberOfDays <- 365 {Normal Year has total days as 365}
4.3 End If
4.4 Output numberOfDays
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.