Question 4
OCR Computer Science June 2018 Paper 2GCSE21 marks
On the specification
- (a)(i)
- 2.2 Programming techniques
- (a)(ii)
- 2.1 Algorithms2.2 Programming techniques
- (b)(i)
- 2.2 Programming techniques
- (b)(ii)
- 2.2 Programming techniques2.3 Producing robust programs
- (c)(i)
- 2.1 Algorithms
- (c)(ii)
- 2.1 Algorithms
Question text
4 A library gives each book a code made from the first three letters of the book title in upper case, followed by the last two digits of the year the book was published. For example, “Poetry from the War”, published in 2012 would be given the code POE12. (a) (i) Complete the following pseudocode for a function definition that will take in the book title and year as parameters and return the book code. 1 function librarycode(title, ) 2 parta = title.subString(0, ) 3 partb = year.subString(2, 2) 4 parta.upper + partb 5 endfunction [3] (ii) Use pseudocode to write an algorithm that does the following : • Inputs the title and year of a book from the user. • Uses the librarycode function above to work out the book code. • Permanently stores the new book code to the text file bookcodes.txt [6] (b) Functions and procedures are both examples of sub programs. (i) Describe one difference between a function and a procedure. [2] (ii) Describe two benefits to a programmer of using sub programs. [4] (c) The library sorts their books based on the book code. (i) Show the steps that a merge sort would take to put the following list of book codes into ascending alphabetical order (from A to Z). POE12 , BAC97 , FLY77 , JAV16 , TAL86 , AND18 , ZAR09 , HOP86 [4] (ii) Explain one advantage of a merge sort compared to a bubble sort. [2]