ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
13 marks · Data types and structures
A program is required to store and process the book data. A sample of the data stored is shown below. Title Author Publication Year Price The Diary Ann Laird 1917 15.98 Animal Park George Smith 1995 9.99 Animal Park George Smith 1945 9.51 Animal Park George Smith 1937 12.99 Coding 101 Aisha Khan 2005 12.34 Coding 101 Joe Brand 2013 14.99 Pride Julia Workman 2001 11.45 Pride Julia Workman 2015 15.29 … … … … Using a programming language of your choice, define a suitable record data structure to store a book’s data. Using a programming language of your choice, declare a variable that could be used to store data for 2000 books. Your answer should make use of the record data structure defined in part (i). An author can publish a book under the same title in different years. One feature of the program is to display the earliest publication year of a book when the user enters a title and author. The top‑level design for this feature is shown below. 1. Read the data from a text file into an array of records. 2. Ask user to enter the title and author to search for. 3. Find the position in the array of records of the earliest publication year of the book with the title and author entered in step 2. 4. Display the earliest publication year of the book with the title and author entered in step 2. If no match is found, display a message indicating this. Complete the table below to show the missing data flow for steps 1, 3 and 4. Step IN OUT 1 2 searchTitle, searchAuthor 3 foundPosition 4 Using a programming language of your choice, write the code for step 3. Your answer should use the record data structure and variable declared in part (a). A book shop has a collection of 2000 books. The title, author, publication year and price of each book is stored in a text file.
• record declaration • 4 appropriate fields within a record If data types are indicated they must be appropriate. Example answer: RECORD book IS {STRING title, STRING author, INTEGER year, REAL buyingPrice } • array of 2000 elements • using data structure from (i) Allow indexing from 1 to 2000. Award 1 mark for books = [Book()]*2000 books = [Book]*2000 Example answer: DECLARE books AS ARRAY OF book INITIALLY []*2000 Step1 OUT: • books() Step 3 IN: • books(), searchTitle, searchAuthor Step 4 IN: • foundPosition, books() Array passed out in step 1 does not need to match part(a) but must avoid confusion with specific fields. For each step the mark is awarded for the correct parameter(s) with no additional parameters. If candidate passes out parallel arrays/fields: • do not award step 1 • step 3 IN: • year()/array().year, title()/array().title, author()/array().author • step 4 IN: year()/array().year • suitable initialisation and update of foundPosition • suitable initialisation and update firstYear • if condition = searchTitle and condition = searchAuthor • if condition < firstYear with loop to iterate through all elements of array • array name matching to (a) • use of field name(s) in IF condition (title, author, year) Award 1 mark for each bullet. At bullet 2,3,4 do not penalise if parallel arrays are used. If parallel arrays are used do not award bullets 5 and 6. Array index must be used correctly. Example answer: SET foundPosition TO -1 SET firstYear TO <any suitable large value> FOR x FROM 0 to length(books)-1 DO IF books[x].title = searchTitle AND books[x].author = searchAuthor AND books[x].year < firstYear THEN SET foundPosition TO counter SET firstYear TO books[x].year END IF END FOR