Paper 2 scenario practice
Library — search a 2D array of books
The scenario
A small library tracks 5 books in a 2D array Books[1:5, 1:4]. Each row stores ONE book; the four columns store: column 1 = TITLE, column 2 = AUTHOR, column 3 = YEAR, column 4 = NUMBER OF COPIES.
For simplicity, all four columns store STRING values (the year and copies are stored as text — no arithmetic is needed in this scenario).
The librarian wants a program that:
1. Has the 5 books already loaded in the array. (You do NOT need to load them — assume they are present.)
2. INPUTS a title to search for.
3. Searches column 1 of the array for the matching title.
4. If found: outputs the book's TITLE, AUTHOR, YEAR, and COPIES, each on a separate line with a label.
5. If not found: outputs a message saying the title was not found in the library.
Write a program in pseudocode (or a high-level language of your choice). Marks will be awarded for correct 2D array indexing, search logic, and output formatting.
Marking scheme — total 15 marks
Cambridge IGCSE 0478 Paper 2
- 2Declare variables: DECLARE the target string, the row counter, and the Found flag with sensible types. Initialise Found ← FALSE.
- 1Read the target: INPUT the title to search for.
- 4Loop and search: WHILE loop visiting each row 1 to 5, comparing Books[i, 1] against the target. Stop when Found becomes TRUE OR when the row counter exceeds 5. Use the 2D array correctly: Books[row, column].
- 4Output the matched book: When found, output Books[i, 1], Books[i, 2], Books[i, 3], Books[i, 4] each on its own line with a label like 'Title: ', 'Author: ', etc. Each label paired with the correct column.
- 2Not-found case: After the loop, IF Found = FALSE THEN output a not-found message. Use IF/ELSE structure (not two separate IFs).
- 2Program structure and naming: Code reads top-to-bottom; clear identifiers; WHILE/ENDWHILE properly paired; IF/ENDIF visible.
Hints — reveal one at a time, only if stuck
Your pseudocode workspace
1 line