Question 5
OCR Computer Science June 2022 Computer systems (H446-01)A level30 marks
On the specification
- (a)(i)
- 2.2 Problem solving and programming
- (a)(ii)
- 2.2 Problem solving and programming
- (a)(iii)
- 2.2 Problem solving and programming
- (b)(i)
- 1.2 Software and software development
- (b)(ii)
- 1.2 Software and software development
- (c)
- 1.2 Software and software development
- (d)
- 1.2 Software and software development
- (e)(i)
- 2.2 Problem solving and programming
- (e)(ii)
- 1.4 Data types, data structures and algorithms
- (e)(iii)
- 1.4 Data types, data structures and algorithms
- (f)
- 1.2 Software and software development
Question text
5 A programmer creates this function shown in Fig. 5 using a high-level language. function mystery(x,y) total = x + y while x >= 10 then x = x – 10 y = y – 10 total = total + x + y endwhile return total endfunction Fig. 5 (a) (i) State the value output by the line print(mystery(10,20)) [1] (ii) State the value output by the line print(mystery(0,70)) [1] (iii) State the value output by the line print(mystery(45,55)) [1] (b) Before the code in Fig. 5 can be executed, a translator must be used. (i) State the purpose of a translator. [1] (ii) Explain two differences between a compiler and an interpreter. Difference 1 Difference 2 [4] (c) For each statement shown in Table 5, tick (✓) one box in each row to indicate which stage of compilation each action takes place at. Lexical Syntax Code analysis analysis generation Comments and whitespace are removed Keywords are replaced with tokens Object code is created Symbol table created for variables Builds an abstract syntax tree Table 5 [5] (d) Describe the purpose of code optimisation. [2] (e) The programmer creates another function to count and return how many capital letters are in a string that is passed into the function as a parameter. The asc() function takes in a character and returns its ASCII value. For example asc("A") returns 65. Capital letters have ASCII values between 65 and 90 inclusive. (i) Complete the function below. function countCapitals(text) // initialise counter to 0 capCount = 0 // loop through each character in the string passed in for x = 0 to text.length-1 c = text.subString(x, 1) // check if character is a capital if asc(c) >= 65 // if so, increment counter endif next x endfunction [3] (ii) Give one similarity between ASCII and Unicode. [1] (iii) Give two differences between ASCII and Unicode. Difference 1 Difference 2 [2] (f)* The programmer has been asked by a client to create a complex computer program. Compare the spiral model and waterfall lifecycle methodologies for this task. You should include the following in your answer: • how both methodologies could be used to develop a complex computer program • the benefits of each methodology for this task • the drawbacks of each methodology for this task. [9]