9618/21/M/J/21 question 2: worked solution (May/June 2021, paper 21)

Show as plain text

Cambridge AS Level Computer Science 9618 · 12.2 Program Design Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 2 of 3. Q10 9618/21/M/J/21 original Q2 Structured · 13 marks Worked solution (a) A structure chart shows each module as a box, with lines from a calling module down to the modules it calls. Draw four boxes: UpdateLoan() at the top, LoanExtend() and LoanReturn() below it, and CheckReserve() below LoanExtend(). [1] UpdateLoan() calls only one of the two modules, so draw a selection diamond on UpdateLoan() where its two lines start. Do not draw an iteration (loop) arrow. [1] On the line to LoanExtend() draw two parameters going down (open circle, arrow down): LoanID and BookID . Draw one flag going up (filled circle, arrow up) for the TRUE/FALSE result. [1] On the line from LoanExtend() to CheckReserve() draw BookID going down and a flag going up for the TRUE/FALSE result. [1] On the line to LoanReturn() draw LoanID and BookID going down, and one data item going up (open circle, arrow up) for the REAL fine. [1] (b) A header starts with PROCEDURE because nothing is returned. Fine is changed by the module and the new value is needed by the caller, so it is passed BYREF . PROCEDURE LoanReturn(LoanID, BookID : STRING, BYREF Fine : REAL) First part of the header: PROCEDURE LoanReturn(LoanID, BookID : STRING, [1] Second part of the header: BYREF Fine : REAL) [1] (c) Read the first value, use it to start Max and Total, then loop for the other 49 values. At the end take Max away from Total and divide by 49. START INPUT Num Set Max to Num Set Total to Num Set Count to 2 Is Count = 51 ? NO → INPUT Num Set Total to Total + Num Is Num > Max ? YES → Set Max to Num Increment Count go back to 'Is Count = 51 ?' YES → Set Av to (Total - Max) / 49 OUTPUT Max, Av END Set Max to the first value input [1] Set Total to zero (or to the first value) before adding [1] A loop that inputs the other 49 values (50 in total), for example using Count [1] Add every value input to Total [1] Inside the loop, set Max to Num when Num > Max [1] After the loop, work out (Total - Max) / 49 and output Max and the average [1] Other correct flowcharts also score, for example setting Total to 0 and then inputting all 50 values in the loop. KEY IDEA A structure chart shows who calls whom and the data passed; a flowchart needs set-up, a loop with a running maximum and total, then the output. TOTAL 13 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Papersdock. Tap the picture to open it on YouTube.