Question 4

OCR Computer Science June 2023 Algorithms and programming (H446-02)A level8 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)
2.2 Problem solving and programming
(c)
2.1 Elements of computational thinking2.2 Problem solving and programming
Question text

4 A programmer has designed a program that includes a reusable program component. (a) The reusable program component is a function called isInteger(). This will take a string as an argument and then check that each digit is between 0 and 9. For example if 103 is input, it will check that the digits 1, 0 and 3 are each between 0 and 9. The asc() function returns the ASCII value of each digit. For example asc("1") returns 49. The ASCII value for 0 is 48. The ASCII value for 9 is 57. 1 function isInteger(number) 2 result = true 3 for count = 0 to number.length-1 4 asciiValue = asc(number.substring(count, 1)) 5 if not(asciiValue >= 48 and asciiValue <= 57) then 6 result = false 7 endif 8 next count 9 return result 10 endfunction (i) Identify one identifier used in the function isInteger(). [1] (ii) Give the line number where the branching (selection) construct starts in the function isInteger(). [1] (iii) Give the line number where the iteration construct starts in the function isInteger(). [1] (b) Describe the purpose of the following lines in the function isInteger(). Line 03 Line 04 Line 09 [3] (c) Give two reasons why reusable program components are used in programs. 1 2 [2]