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

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

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

Official answer for Question 3

Part (e)

(ii)

Question 1

mark per bullet to max 5

✓
•
✓
Prompt to user for position down and across, read positions input as an IntegerValidation for position row – between
✓
0 and 9
✓
•
✓
Validation for position column- between 0 and 29
✓
•
✓
Exception handling/pass for validation
✓
•
✓
Ask for repeated input until valid (for both row and column)
✓
•
✓
Call Island.DigHole method with the coordinates
✓
Example Python
✓
def StartDig() :
✓
Valid = False
✓
while not Valid :
✓
# validate down position

Question 1

✓
try:
✓
x = int(input("position down <0 to 9> ? "))

Question 1

✓
if x >= 0 and x <= 9 :

Question 1

✓
Valid = True
✓
except:
✓
Valid = False
✓
Valid = False
✓
while not Valid :
✓
# validate across position
✓
try :
✓
y = int(input("position across <0 to 29> ? "))

Question 1

✓
if y >= 0 and y <= 29 :

Question 1

✓
Valid = True
✓
except :
✓
Valid = False
✓
island.DigHole(x, y)

Question 1

✓
return
✓
9608/42
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example Pascal
✓
procedure StartDig;
✓
var xString, yString : String;
✓
x, y : integer;
✓
begin
✓
Valid := False;
✓
repeat
✓
Write('position down <0 to 9>? '); ReadLn(xString);

Question 1

✓
try
✓
x := StrToInt(xString);
✓
if (x >= 0) AND (x <= 9)

Question 1

✓
then
✓
Valid := True;
✓
except
✓
Valid := False;
✓
until Valid;
✓
Valid := False;
✓
repeat
✓
Write(position across <0 to 29> ? '); ReadLn(yString);

Question 1

✓
try
✓
y := StrToInt(yString);
✓
if (y >= 0) AND (y <= 29)

Question 1

✓
then
✓
Valid := True;
✓
except
✓
Valid := False;
✓
until Valid;

Question 1

✓
island.DigHole(x,y);

Question 1

✓
end;
✓
9608/42
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example VB.NET
✓
Sub StartDig()
✓
Dim x, y As Integer
✓
Dim Valid = False
✓
Do
✓
Console.Write("Position down <0 to 9>? ")
✓
Try
✓
x = CInt(Console.ReadLine())

Question 1

✓
If (x >= 0) AND (x <= 9) Then

Question 1

✓
Valid = True
✓
End If
✓
Catch
✓
Valid = False 'accept different types of exceptions
✓
End Try
✓
Loop Until Valid
✓
Valid = False
✓
Do
✓
Console.Write("Position across <0 to 29> ? ")
✓
Try
✓
y = int(Console.ReadLine())

Question 1

✓
If (y >= 0) AND (y <= 29) Then

Question 1

✓
Valid = True
✓
End IF
✓
Catch
✓
Valid = False
✓
End Try
✓
Loop until Valid

Question 1

✓
island.DigHole(x, y)

Question 1

✓
End Sub

Mark scheme 9608_s17_ms_42.pdf →

Show text version of question

Question 3

Part (e)

(ii)

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

(ii)

The StartDig procedure:

  • prompts the player for a location to dig
  • validates the user input
  • calls the DigHole method from part (e)(i).

Write program code for the StartDig procedure. Ensure that the user input is fully validated.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.......................................................................................................................................[5]

Question 17

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