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

Question 4(b)(i) 2015 · October-November · Paper 22 · 1 mark

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

Official answer for Question 4

Part (b)

(i)

Part (b)

(i)

32 // 33

[1]

Mark scheme 9608_w15_ms_22.pdf →

Show text version of question

Question 4

Part (b)

(i)

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
A
representation of dealing out the cards is shown below:

Card value Suit number 1 2 3 4 5 6 7 8 9 10 11 12 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 10 NewCard ← FALSE 11 WHILE NewCard = FALSE 12 SuitNum ← RANDOM(1,4) // generates a random number 13 CardValue ← RANDOM(1,13) // in the range given 14 IF CardPack[SuitNum, CardValue] = FALSE 15 THEN 16 CardPack[SuitNum, CardValue] ← TRUE 17 NewCard ← TRUE 18 OUTPUT SuitNum, CardValue 19 ENDIF 20 ENDWHILE 21 DealCount ← DealCount + 1 22 ENDWHILE

Question 23

24 // end of main program

Question 25

26 PROCEDURE InitialiseCardPack 27 DECLARE i : INTEGER 28 DECLARE j : INTEGER 29 FOR i ← 1 TO 4 30 FOR j ← 1 TO 13 31 CardPack[i, j] ← FALSE 32 ENDFOR 33 ENDFOR 34 ENDPROCEDURE

Question 9

Study the pseudocode and answer the questions below:

Give the line number for:

(i)

A statement which marks the end of a count controlled loop.

.......................................................................................................................................[1]

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