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 loa...

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

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 positionDevice codeBorrower IDDays on loanReturned
0TB-07104826false
1CA-12109010true
2TB-151037614false

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]

Answer Details

(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]

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