Question 1 Report
A program reads five numbers. It adds only positive numbers to total, then displays the total. The flowchart below represents the algorithm. X and Y label flowchart symbols. Labels A and B are missing instructions.
After instruction B, the algorithm repeats until count = 5, then displays total.
(a) Identify the names of symbols X and Y. [2]
(b) Complete A. [2]
(c) State the purpose of setting total to 0 at the start. [1]
(d) Give the value displayed for the input data 4, -2, 7, 0, 3. [2]
(e) Explain why instruction B must happen for every input number, including zero and negative numbers. [3]
(f) Convert the loop-ending condition into a pseudocode line. [2]
(g) Complete B using pseudocode. [2]
(a) X is an input/output symbol (parallelogram), and Y is a decision symbol (diamond) [2].
(b) A must be number > 0 [2]. Only a positive input follows the Yes route and is added.
(c) Setting total ← 0 initialises the accumulator, so addition starts at zero rather than an old or undefined value [1].
(d) Positive inputs are 4, 7 and 3. \[4+7+3=14\] The displayed total is 14 [2].
(e) B must run for every input because count counts numbers entered, not positive numbers. Incrementing it every time ensures exactly five inputs are processed. Incrementing only after positives could make the algorithm wait for extra values and fail to terminate after five inputs [3].
(f) The loop-ending pseudocode is UNTIL count = 5 [2].
(g) B is count ← count + 1 [2].
Everything you need to excel in your exams