Question 5

OCR Computer Science June 2023 Algorithms and problem solving (H046-02)AS11 marks

On the specification

(a)(i)
2.2 Problem solving and programming
(a)(ii)
2.2 Problem solving and programming
(b)
2.2 Problem solving and programming
(c)
2.2 Problem solving and programming
(d)(i)
2.2 Problem solving and programming
(d)(ii)
2.2 Problem solving and programming
Question text

5 Layla writes a pseudocode algorithm to: • input 20 positive numbers into a 0-indexed 1-dimensional array • output the average (mean) number as a decimal • output the smallest number • output the largest number. The pseudocode algorithm is shown. It contains various errors. 1 total = 1 2 smallest = 9999 3 largest = -1 4 for x = 0 to 21 5 dataArray[x] = input("Enter a number") 6 total = total + dataArray[x] 7 if dataArray[x] < largest then 8 largest = dataArray[x] 9 endif 10 if dataArray[x] < smallest then 11 smallest = dataArray[x] 12 endif 13 next x 14 print("Average = " + total * 20) 15 print("Smallest = " + smallest) 16 print("Largest = " + largest) (a) (i) Identify the construct used on lines 01 to 03 in the algorithm. [1] (ii) Identify the construct used on lines 10 to 12 in the algorithm. [1] (b) Identify two variables used in this algorithm. 1 2 [2] (c) The algorithm that Layla has written has many errors. Identify the line number of four different errors and write the corrected line of code. Error 1 line number Error 1 correction Error 2 line number Error 2 correction Error 3 line number Error 3 correction Error 4 line number Error 4 correction [4] (d) dataArray is defined as a local variable within the main program. (i) State what is meant by a ‘local variable’. [1] (ii) Give one benefit and one drawback of declaring dataArray as a local variable in the main program. Benefit Drawback [2]