Question 1 Report
Table 1 shows part of a library program file. A librarian uses the program to track loans of portable devices. Each row is one record in an array called loans. The return date is displayed in the form day/month/year.
| Array position | Device code | Borrower ID | Days on loan | Returned |
|---|---|---|---|---|
| 0 | TB-07 | 10482 | 6 | false |
| 1 | CA-12 | 10901 | 0 | true |
| 2 | TB-15 | 10376 | 14 | false |
The code editor will use the data to produce an overdue list. The librarian checks that each value has an appropriate data type before the file is saved.
(a) Identify the array position of device code TB-15. [1]
(b) Write a suitable data type for Days on loan and a suitable data type for Returned. [2]
(c) Give two reasons why the device code should be stored as a string. [2]
(d) Complete the condition that identifies a device which has been on loan for more than 10 days and has not been returned.IF loans[i].daysOnLoan _____ 10 AND loans[i].returned _____ THEN [2]
(a) Device code TB-15 is at array position 2. [1]
(b) Days on loan should be an integer [1], since the table uses whole days. Returned should be a Boolean [1], since it is either true or false. [2]
(c) The device code should be stored as a string because it contains letters [1] and because the hyphen is a meaningful part of the code [1]. It is an identifier, not a quantity for arithmetic, and string storage also preserves any leading zeroes. [2]
(d) “More than 10” requires >, not >=. “Has not been returned” can be tested by = false or NOT false:
IF loans[i].daysOnLoan > 10 AND loans[i].returned = false THEN
The comparison gains [1] and the returned test gains [1]. [2]
Everything you need to excel in your exams