Question 10

AQA Computer Science June 2018 Paper 1GCSE7 marks

On the specification

10.1
3.1 Fundamentals of algorithms3.2 Programming
10.2
3.2 Programming
10.3
3.2 Programming
10.4
3.1 Fundamentals of algorithms
Question text

10 The subroutine in Figure 3 is used to authenticate a username and password combination. • Array indexing starts at 0. • Line numbers are included but are not part of the algorithm. Figure 3 1 SUBROUTINE Authenticate(user, pass) 2 us  ['dave', 'alice', 'bob'] 3 ps  ['abf32', 'woof2006', '!@34E$'] 4 z  0 5 correct  false 6 WHILE z < 3 7 IF user = us[z] THEN 8 IF pass = ps[z] THEN 9 correct  true 10 ENDIF 11 ENDIF 12 z  z + 1 13 ENDWHILE 14 RETURN correct 15 ENDSUBROUTINE 10.1 Complete the trace table for the following subroutine call: Authenticate('alice', 'woof2006') [3 marks] z correct 10.2 State the value that is returned by the following subroutine call: Authenticate('bob', 'abf32') [1 mark] 10.3 Lines 7 and 8 in Figure 3 could be replaced with a single line. Shade one lozenge to show which of the following corresponds to the correct new line. [1 mark] A IF user = us[z] OR pass = ps[z] THEN B IF user = us[z] AND pass = ps[z] THEN C IF NOT (user = us[z] AND pass = ps[z]) THEN 10.4 A programmer implements the subroutine shown in Figure 3. He replaces line 9 with RETURN true He also replaces line 14 with RETURN false Explain how the programmer has made the subroutine more efficient. [2 marks]