Past-paper question · 2017 May-June · Paper 42 · Q3(e)(i)

Question 3(e)(i) 2017 · May-June · Paper 42 · 3 marks

Original past-paper question for 3(E)(I)
Original past-paper question for 3(E)(I)
Original past-paper question for 3(E)(I)
Original past-paper question for 3(E)(I)
Original past-paper question for 3(E)(I)
Original past-paper question for 3(E)(I)
Reveal official mark-scheme answer Official mark-scheme answer for 3(E)(I)Official mark-scheme answer for 3(E)(I)

Official answer for Question 3

Part (e)

(i)

Question 1

mark per bullet

Question 3

  • Method heading, with two parameters & Declaring constants for Treasure, Hole and FoundTreasure
  • Check if treasure at parameter locations
  • Set to FoundTreasure (X) and Set to Hole (O)
✓
Example Python
✓
def DigHole(self, x, y)
✓
:
✓
Treasure = 'T'
✓
Hole = 'O'

Question 1

✓
Foundtreasure = 'X'
✓
if self.__Grid[x][y]
✓
== Treasure:

Question 1

✓
self.__Grid[x][y]
✓
= Foundtreasure
✓
else :

Question 1

✓
self.__Grid[x][y]
✓
= Hole
✓
return
✓
Example Pascal
✓
procedure IslandClass.DigHole(x, y : integer);
✓
const Treasure = 'T';
✓
const Hole = 'O';
✓
const Foundtreasure = 'X';

Question 1

✓
begin
✓
if Grid[x, y] = Treasure

Question 1

✓
then
✓
Grid[x, y] := Foundtreasure
✓
else
✓
Grid[x, y] := Hole;

Question 1

✓
end;
✓
9608/42
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example VB.NET
✓
Public Sub DigHole(x As Integer, y As Integer)
✓
Const Treasure = "T"
✓
Const Hole = "O"
✓
Const Foundtreasure = "X"

Question 1

✓
If Grid(x, y) = Treasure Then

Question 1

✓
Grid(x, y) = Foundtreasure
✓
Else
✓
Grid(x, y) = Hole

Question 1

✓
End If
✓
End Sub
✓
9608/42
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s17_ms_42.pdf →

Show text version of question

Question 3

Part (e)

(i)

Question 3

A programmer is writing a treasure island game to be played on the computer. The island is

a rectangular grid, 30 squares by 10 squares. Each square of the island is represented by an element in a 2D array. The top left square of the island is represented by the array element [0, 0]. There are 30 squares across and 10 squares down.

The computer will:

  • generate three random locations where treasure will be buried
  • prompt the player for the location of one square where the player chooses to dig
  • display the contents of the array by outputting for each square:
  • '.' for only sand in this square
  • 'T' for treasure still hidden in sand
  • 'X' for a hole dug where treasure was found
  • 'O' for a hole dug where no treasure was found.

Here is an example display after the player has chosen to dig at location [9, 3]:

.............................. .............................. .............................. .............................. .............................. ........T..................... .............................. .............................. .........T.................... ...X..........................

The game is to be implemented using object-oriented programming.

The programmer has designed the class IslandClass. The identifier table for this class is:

Identifier Data type Description 2D array to represent the Grid ARRAY[0 : 9, 0 : 29] OF CHAR squares of the island instantiates an object of class Constructor() IslandClass and initialises all squares to sand generates a pair of random numbers used as the grid HideTreasure() location of treasure and marks the square with 'T' takes as parameters a valid grid location and marks the DigHole(Row, Column) square with 'X' or 'O' as appropriate takes as parameter a valid grid location and returns the GetSquare(Row, Column) CHAR grid value for that square from the IslandClass object

Question 11

(i)

The DigHole method takes two integers as parameters. These parameters form a valid

grid location. The location is marked with 'X' or 'O' as appropriate.

Write program code for the DigHole method. The values to represent treasure, found treasure and hole should be declared as constants.

Programming language used ............................................................................................

Program code ....................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

.......................................................................................................................................[3]

Question 16

Topic relevance

Why this question appears here

98% assigned-topic match · Further programming › Programming paradigms

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_s17_qp_42.pdf

Keep practising this topic