Question 3

OCR Computer Science June 2017 Paper 2A level19 marks

On the specification

(a)(i)
2.1 Elements of computational thinking
(a)(ii)
2.1 Elements of computational thinking
(b)
2.2 Problem solving and programming
(c)
1.4 Data types, data structures and algorithms2.2 Problem solving and programming
(d)
2.2 Problem solving and programming1.4 Data types, data structures and algorithms
Question text

3 An encryption routine reads a line of text from a file, reverses the order of the characters in the string and subtracts 10 from the ASCII value of each letter, then saves the new string into the same file. The program is split into sub-procedures. Three sub-procedures are described as follows: • Read string from file • Push each character of the string onto a stack • Read and encrypt each character message (a) (i) Identify one further sub-procedure that could be used in the program. [1] (ii) Describe two advantages of splitting the problem into sub-procedures. 1 2 [4] (b) A function, readMessage: • takes the file name as a parameter • reads and returns the line of text Complete the pseudocode algorithm for readMessage: function (fileName) messageFile = openRead( ) message = messageFile.readLine() messageFile. return endfunction [4] (c) A function, push, can be used to add a character to a stack. For example: theStack.push("H") places the character H onto the stack, theStack. A procedure, pushToStack, takes a string as a parameter and pushes each character of the message onto the stack, messageStack. Complete the procedure below. Add comments to explain how your code works. procedure pushToStack(message) endprocedure [5] (d) Describe the steps that the program would have to take in order to encrypt the characters stored in the stack, and save them in a single variable. [5]