Question 6

OCR Computer Science June 2022 Algorithms and programming (H446-02)A level9 marks

On the specification

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

6 A card game uses a set of 52 standard playing cards. There are four suits; hearts, diamonds, clubs and spades. Each suit has a card with a number from; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13. The card game randomly gives 2 players 7 cards each. The unallocated cards become known as the deck. The players then take it in turns to turn over a card. A valid move is a card of the same suit or the same number as the last card played. The winner is the first player to play all of their cards. (a) One component of the game is checking if a move is valid. Identify three other components of the game. 1 2 3 [3] (b) A function, checkValid(), takes the card the player has selected, and the last card played as parameters. It returns true if the player’s move is valid and returns false if the player’s move is not valid. (i) State the reason why checkValid() is a function and not a procedure. [1] (ii) The programmer will use a branching (selection) construct to make decisions. Describe the decisions that will be made in the checkValid() function and how these change the return values. [3] (c) The cards are held in the 2D array cards. The first index stores the card number and the second index stores the suit, both as strings. Write a pseudocode statement or program code to declare the array cards. [2]