Question Constellation Sign up for free

AQA · GCSE · Computer Science · Higher

Tracing array totals through iteration

Q08.0 6 marks

Figure 6 shows an algorithm, represented using pseudo-code.

Figure 6
days ← [10, 15, 4]
sales ← [20, 33, 12]
weeks ← [0, 0, 0]
FOR i ← 0 TO 2
daysTotal ← days[i] + sales[i]
weeks[i] ← daysTotal DIV 7
ENDFOR
weeksTotal ← weeks[0] + weeks[1] + weeks[2]
OUTPUT weeksTotal

The DIV operator is used for integer division.

Complete the trace table for the algorithm in Figure 6. Part of the table has already been filled in. You may not need to use all the rows in the table.

Practice unavailable

This question can be viewed, but its original response format is not available for practice yet.

Write your answer first. You can study the marking guidance whenever you need it.

Study the marking See what earns credit and compare it with a full-mark answer.

Marking points

  1. 1 Traces i as 0, 1, 2.
  2. 2 Calculates the first daysTotal as 30.
  3. 3 Calculates the later daysTotal values as 48 and 16.
  4. 4 Updates weeks[0] to 4.
  5. 5 Retains and updates the entire weeks array through all three iterations.
  6. 6 Places only the final total 12 in weeksTotal, subject to official follow-through guidance.

Why this answer loses marks

On each iteration I reset the array and wrote only the newest changed element.

The trace must retain earlier array updates, or the final state and total will no longer follow the algorithm.