Fig. 1 shows a warehouse robot program. Each robot reads a shelf code and a number of items to collect. The main algorithm calls one subprogram to validate ...

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

Question 1 Report

Fig. 1 shows a warehouse robot program. Each robot reads a shelf code and a number of items to collect. The main algorithm calls one subprogram to validate the shelf code and another to calculate the travel distance. Table 1 gives data from four robot test runs. Shelf codes from A01 to A20 are on the left aisle, and B01 to B20 are on the right aisle.

collectOrdervalidShelf(code)returns TRUE or FALSEtravelMetres(code)returns a number© EAGLE BEACON GLOBAL
Shelf code inputItems requestedvalidShelf resulttravelMetres result in m
A046TRUE16
B122TRUE48
C035FALSEnot called
A211FALSEnot called

If validShelf returns FALSE, the program must display "Code error" and must not call travelMetres. The programmer is checking that data is passed correctly between subprograms.

(a) Identify the return data type of each subprogram in Fig. 1. [2]
(b) State the two invalid shelf codes in Table 1 and give the displayed message for either one. [3]
(c) Complete the main algorithm using the correct subprogram calls. [4]

INPUT shelfCode
IF __________ THEN
  distance <- __________
  DISPLAY distance
ELSE
  DISPLAY "Code error"
ENDIF

(d) Use Table 1 to write two test cases for travelMetres, including an input and its expected returned number. Give one reason why it should not be called for C03. [5]

Answer Details

(a) validShelf returns a BOOLEAN, either TRUE or FALSE. travelMetres returns an INTEGER or number representing metres. [2]

(b) The invalid codes are C03 and A21. For either invalid code, the program displays "Code error". [3]

(c) The completed algorithm is:

INPUT shelfCode
IF validShelf(shelfCode) THEN
  distance <- travelMetres(shelfCode)
  DISPLAY distance
ELSE
  DISPLAY "Code error"
ENDIF

The validation function must be called first. The distance function is called only if the result is TRUE. [4]

(d) Two test cases for travelMetres are:

Input shelf codeExpected returned distance
A0416 m
B1248 m

travelMetres should not be called for C03 because C03 is not a valid shelf code, so there is no defined travel distance for it. [5]

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