Past-paper question · 2015 October-November · Paper 22 · Q4(b)

Question 4(b) 2015 · October-November · Paper 22 · 0 marks

Original past-paper question for 4(B)
Original past-paper question for 4(B)
Original past-paper question for 4(B)
Original past-paper question for 4(B)
Original past-paper question for 4(B)
Reveal official mark-scheme answer

Official answer for Question 4

Part (b)

Part (b)

(i)

32 // 33

[1]

Mark scheme 9608_w15_ms_22.pdf →

Show text version of question

Question 4

Part (b)

Question 4

The standard pack of playing cards has four suits – called Clubs, Diamonds, Hearts and Spades. Each card has a value shown by its number or a name: 1 (Ace), 2, 3, … 10, 11 (Jack), 12 (Queen), 13 (King). The pack of cards has one combination for each suit and value.

A
program is to be written which simulates a magician dealing all 52 cards from the card pack.

The program generates pairs of random numbers: • the first, in the range 1 to 4, to represent the suit • the second, in the range 1 to 13, to represent the card value

Part (b)

A representation of dealing out the cards is shown below:

Card value Suit number

Question 1

Question 2

Question 3

Question 4

Question 5

Question 6

Question 7

Question 8

Question 9

Question 10

Question 11

Question 12

Question 13

1 (Clubs) F F F F F F F F F F T F F 2 (Diamonds) F F F F F F F F F F F F F 3 (Hearts) F F T F F F F F F F F F F 4 (Spades) F F F F F F F F F F F F F The table shows two cards have been dealt so far; the 3 of Hearts and the Jack of Clubs. When each card is dealt, the appropriate cell changes from F to T. The program will output the suit and the card value in the order in which the cards are dealt.

Question 7

Question 4(b) continues on page 8.

Question 8

The program design in pseudocode is produced as follows: 01 DECLARE SuitNum : INTEGER 02 DECLARE CardValue : INTEGER 03 DECLARE DealCount : INTEGER 04 DECLARE NewCard : BOOLEAN 05 DECLARE CardPack ........................................................................................................... 06 07 CALL InitialiseCardPack ← 08 DealCount 0 09 WHILE DealCount <> 52 ←

Question 10

NewCard FALSE

Question 11

WHILE NewCard = FALSE ←

Question 12

SuitNum RANDOM(1,4) // generates a random number ←

Question 13

CardValue RANDOM(1,13) // in the range given

Question 14

IF CardPack[SuitNum, CardValue] = FALSE

Question 15

THEN ←

Question 16

CardPack[SuitNum, CardValue] TRUE ←

Question 17

NewCard TRUE

Question 18

OUTPUT SuitNum, CardValue

Question 19

ENDIF

Question 20

ENDWHILE ←

Question 21

DealCount DealCount + 1

Question 22

ENDWHILE

Question 23

Question 24

// end of main program

Question 25

Question 26

PROCEDURE InitialiseCardPack

Question 27

DECLARE i : INTEGER

Question 28

DECLARE j : INTEGER ←

Question 29

FOR i 1 TO 4 ←

Question 30

FOR j 1 TO 13 ←

Question 31

CardPack[i, j] FALSE

Question 32

ENDFOR

Question 33

ENDFOR

Question 34

ENDPROCEDURE

Question 9

Study the pseudocode and answer the questions below: Give the line number for:

Topic relevance

Why this question appears here

82% assigned-topic match · Programming › Constructs

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_w15_qp_22.pdf

Keep practising this topic