A library stores data about books using this record structure.
RECORD Book
title : String
year : Integer
onLoan : Boolean
ENDRECORD(a) Write AQA pseudocode to create a variable b1 holding a Book record for Holes, published in 1998, which is currently on loan. [2]
(b) The array library contains many Book records. Write an algorithm, using AQA pseudocode, that outputs the title of every book that was published before 2000 and is not on loan. [4]
- (a) b1 ← Book(…) i.e. a new Book record assigned to b1; allow fields assigned separately, e.g. b1.title ← 'Holes'(1)
- (a) Values in the correct field order: Book('Holes', 1998, True); if fields assigned separately, all three correct values (title 'Holes', year 1998, onLoan True)(1)
- (b) Loop that visits every record in library (e.g. FOR i ← 0 TO LEN(library) − 1); accept FOR b IN library, or a WHILE loop with a correctly incremented index(1)
- (b) Accesses fields using dot notation, e.g. library[i].year(1)
- (b) Correct condition: year < 2000 AND onLoan = False; accept year ≤ 1999; accept NOT library[i].onLoan; accept two nested IF statements(1)
- (b) Outputs library[i].title (inside the IF)(1)
- Answer: (a) b1 ← Book('Holes', 1998, True)
(b)FOR i ← 0 TO LEN(library) - 1 IF library[i].year < 2000 AND library[i].onLoan = False THEN OUTPUT library[i].title ENDIF ENDFOR - Examiner tip: Use AND, not OR, when both conditions must be true. Also, 'before 2000' means < 2000, not ≤ 2000.