Fig. 1 shows a vending-machine algorithm for choosing a hot drink. The customer enters a number from 1 to 3. The program uses a selection structure to displ...

Assessment: Computer Science 4CP0 | Paper 2 Mock 01 | Written Paper 2 Subject: Computer Science - 4CP0

Question 1 Report

Fig. 1 shows a vending-machine algorithm for choosing a hot drink. The customer enters a number from 1 to 3. The program uses a selection structure to display the chosen drink and then deduct its price from the credit. Number 1 is tea, number 2 is coffee and number 3 is soup. Any other number causes an error message. The machine must not dispense a drink when the input is invalid.

Fig. 1: drink selection pseudocode01 INPUT choice02 IF choice = 1 THEN DISPLAY "tea"03 ELSEIF choice = 2 THEN DISPLAY "coffee"04 ELSEIF choice = 3 THEN DISPLAY "soup"05 ELSE DISPLAY "error"

(a) Identify the displayed word for input 2. [1]
(b) State the displayed word for input 3. [1]
(c) Write one input that produces error. [1]
(d) Give the line that first tests whether the input is 2. [1]
(e) Use the figure to state how many recognised drink choices are available. [1]

Answer Details

(a) Input 2 matches the coffee condition, so the displayed word is coffee. [1]

(b) Input 3 matches the next recognised condition, so the displayed word is soup. [1]

(c) An input such as 4 produces error. [1] Any number other than 1, 2 or 3 is valid test data for this route.

(d) The test for input 2 is on line 03: ELSEIF choice = 2 THEN DISPLAY "coffee". [1]

(e) There are 3 recognised drink choices. [1]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning