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.
| Shelf code input | Items requested | validShelf result | travelMetres result in m |
|---|---|---|---|
| A04 | 6 | TRUE | 16 |
| B12 | 2 | TRUE | 48 |
| C03 | 5 | FALSE | not called |
| A21 | 1 | FALSE | not 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]
(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 code | Expected returned distance |
|---|---|
| A04 | 16 m |
| B12 | 48 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]
Everything you need to excel in your exams