Past-paper question · 2017 October-November · Paper 43 · Q6(c)(i)

Question 6(c)(i) 2017 · October-November · Paper 43 · 4 marks

Original past-paper question for 6(C)(I)
Original past-paper question for 6(C)(I)
Original past-paper question for 6(C)(I)
Original past-paper question for 6(C)(I)
Original past-paper question for 6(C)(I)
Reveal official mark-scheme answer Official mark-scheme answer for 6(C)(I)Official mark-scheme answer for 6(C)(I)Official mark-scheme answer for 6(C)(I)

Official answer for Question 6

Part (c)

(i)

Question 1

mark per bullet:

  • Function header and ending taking one value as parameter
  • Check if coordinate = 0 (on lower bound)
  • «generate random number (0 or 1)
  • Check if coordinate = 39 (on upper bound)
  • «generate random number (–1 or 0)
  • Generate random number (e.g. –1, 0, 1)
  • Return the generated value
✓
9608/43
✓
Cambridge International AS/A Level – Mark Scheme
✓
October/November
✓
PUBLISHED
✓
2017
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_w17_ms_43.pdf →

Show text version of question

Question 6

Part (c)

(i)

Question 6

A programmer wants to create a computer simulation of animals searching for food in a desert.

The desert is represented by a 40 by 40 grid. Each position in the grid is represented by a pair of coordinates. 'A' represents an animal and 'F' represents food. At the start of the simulation, the grid contains 5 animals and 1 food source.

The following is an example of part of the grid.

0 1 2 3 4 ... 37 38 39 0 A .. 1 F .. 2 .. A 3 A .. ... .. .. .. .. .. .. .. .. .. 38 A .. A 39 ..

A
timer is used. In each time interval, each animal randomly moves 0 or 1 position in a random

direction. The program generates this movement by computing two random numbers, each of which can be –1, 0 or 1. The program adds the first random number to the across number and the second random number to the down number representing the animal’s position.

For example:

  • if 0 and 1 are generated, the across value does not change, the down value increases by 1
  • if –1 and 1 are generated, the across value decreases by 1, and the down value increases

by 1.

Each animal has an individual score. If the animal moves to a position in the grid with food ('F'):

  • the animal’s score increases by 1
  • the food disappears
  • one new animal ('A') is randomly generated and added to the grid (to a maximum of
  • 20 animals)

  • one new food ('F') is randomly generated and added to the grid.

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

The programmer has designed two classes, Desert and Animal.

The Desert class consists of:

  • attributes
  • Grid
  • StepCounter
  • AnimalList
  • NumberOfAnimals
  • methods
  • Constructor
  • IncrementStepCounter
  • GenerateFood
  • DisplayGrid

Each attribute consists of a value and a get and set method that allow access to the attributes.

Question 12

The following table describes the attributes and methods for the Animal class.

Identifier Data type Description Instantiate an object of the Animal class

  • Generate a pair of random numbers
  • Constructor() between 0 and 39.

  • Place animal at that random
  • position.

  • Initialise the animal’s score to 0.
  • Delete the food.
  • Increase the score of the animal that
  • called the method. EatFood() • Call the GenerateFood method of the Desert class.

  • Call the Constructor method of
  • the Animal class.

  • Call the
  • GenerateChangeInCoordinate method for each coordinate (across or down number) of the animal’s Move() position.

  • Moves the animal to the new space.
  • If there is food in the new position,

call the EatFood method. Score INTEGER Initialised to 0 Across INTEGER The across value, between 0 and 39 Down INTEGER The down value, between 0 and 39

Question 13

(i)

The function GenerateChangeInCoordinate:

  • receives a coordinate (across or down number) as a parameter
  • checks whether the coordinate’s value is at a boundary of the grid
  • returns a random change (–1, 0 or 1) that will keep the animal’s position within the

grid.

Write program code for the GenerateChangeInCoordinate function.

Programming language .....................................................................................................

Program code

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

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

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

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

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

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

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

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

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

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

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

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

.......................................................................................................................................[4]

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

Keep practising this topic