Question 4

AQA Computer Science June 2019 Paper 1GCSE9 marks

On the specification

4.1
3.1 Fundamentals of algorithms3.2 Programming
4.2
3.2 Programming
4.3
3.1 Fundamentals of algorithms
4.4
3.2 Programming
Question text

4.1 Complete the trace table for the algorithm shown in Figure 4 for when the user box enters the value 750 when prompted. [4 marks] Figure 4 constant PAYLOAD_SIZE ← 250 constant HEADER_SIZE ← 50 OUTPUT ‘Enter the number of bits of data to be sent’ dataToBeSent ← USERINPUT totalSize ← PAYLOAD_SIZE + HEADER_SIZE numberOfPackets ← 0 REPEAT dataToBeSent ← dataToBeSent – totalSize numberOfPackets ← numberOfPackets + 1 UNTIL dataToBeSent ≤ 0 totalSize dataToBeSent numberOfPackets 750 4.2 State why both PAYLOAD_SIZE and HEADER_SIZE from the algorithm in Figure 4 did not need to be included in the trace table. [1 mark] 4.3 Shade one lozenge to show which of the following best represents the input and output to/from the algorithm in Figure 4. [1 mark] A Input: dataToBeSent, output: numberOfPackets B Input: numberOfPackets, output: totalSize C Input: totalSize, output: dataToBeSent 4.4 A developer looks at the algorithm in Figure 4 and realises that the use of iteration box is unnecessary if they use a combination of the DIV and MOD operators. • DIV calculates integer division, eg 11 DIV 4 = 2 • MOD calculates the remainder after integer division, eg 11 MOD 4 = 3 The programmer realises that she can rewrite the algorithm by replacing the REPEAT-UNTIL structure with code that uses selection, MOD and DIV instead. Complete this new algorithm by stating the code that should be written in the boxes labelled A, B and C. This new algorithm should calculate the same final result for the variable numberOfPackets as the original algorithm in Figure 4. [3 marks] constant PAYLOAD_SIZE ← 250 constant HEADER_SIZE ← 50 OUTPUT ‘Enter the number of bits of data to be sent’ dataToBeSent ← USERINPUT totalSize ← PAYLOAD_SIZE + HEADER_SIZE numberOfPackets ← dataToBeSent DIV totalSize IF A MOD B > 0 THEN numberOfPackets ← C ENDIF A B C