Question 1 Report
A robotics club writes a program to move a greenhouse inspection robot along a bench. Fig. 1 is a flowchart for one scan. The robot reads a moisture value from each plant pot. If the value is below 35, it displays the word WATER; otherwise it displays OK. After either display, the variable pot increases by 1. The robot must stop after it has processed 6 pots. A student has used the wrong comparison in the loop decision.
Fig. 1: greenhouse robot flowchart
(a) Identify the construct represented by the paths that lead to DISPLAY WATER and DISPLAY OK. [1]
(b) Write the display for moisture inputs 34, 35 and 61. [3]
(c) Complete the final decision so that exactly six pots are processed, and write a suitable initial value for pot. [4]
(a) The two alternative paths chosen by the result of moisture < 35? form a selection, also called an IF...ELSE construct. Only one of the two display commands is carried out. [1]
(b) The comparison is strictly below 35, so 35 itself does not satisfy it.
34 < 35 is true, so display WATER. [1]35 < 35 is false, so display OK. [1]61 < 35 is false, so display OK. [1](c) If pot starts at 1 and is increased after each pot, the sixth pot is processed when pot = 6. The loop must therefore continue while pot <= 6; equivalently, it may use pot < 7. [2] A suitable initial value is pot = 1. [2] This avoids stopping after only five pots, which would happen with pot < 6.
Everything you need to excel in your exams