Question 2
OCR Computer Science June 2025 Algorithms and problem solving (H046-02)AS12 marks
On the specification
- (a)
- 1.4 Data types, data structures and algorithms
- (b)(i)
- 1.4 Data types, data structures and algorithms
- (b)(ii)
- 2.2 Problem solving and programming
- (b)(iii)
- 2.2 Problem solving and programming
- (c)
- 2.2 Problem solving and programming
Question text
2 Players in a computer game collect items. Each item has a name, e.g. “Fruit” and a type, e.g. “Apple”. The items for player 1 are stored in a 2D array. The array is 0-indexed. The pseudocode declaration for the array is: array p1Items[10,2] The first dimension stores the item name and the second dimension stores the type. (a) One characteristic of the array is that it has 2 dimensions. Identify two other characteristics of the given array. 1 2 [2] (b) When the game starts, the pseudocode procedure initialiseArray will initialise each name and type in the array to "empty". 1 procedure initialiseArray(p1Items:byRef) 2 counter = 0 3 while counter < 10 4 p1Items[counter, 0] = "empty" 5 p1Items[counter, 1] = "empty" 6 counter = counter + 1 7 endwhile 8 endprocedure (i) State why empty is in speech marks on lines 04 and 05. [1] (ii) Rewrite the code in lines 02 to 07 to use a for loop instead of a while loop. Write your answer using pseudocode or program code. [2] (iii) State one reason why the array should be passed by reference and not by value. [1] (c) When a user collects an item, the name and type are added to the array p1Items. At the end of the game, the name of each item collected is output. Write an algorithm, using pseudocode or program code, to: • output the name of each item in the array • output a suitable message if there are no items in the array. If the item is "empty" it should not be output. [6]