Question 6(c)(ii) 2017 · October-November · Paper 43 · 4 marks
Reveal official mark-scheme answer

Official answer for Question 6
Part (c)
(ii)
Question 1
mark per bullet to max 4
Question 4
- Procedure move header, no parameters
- Calling GenerateDirection twice sending across and down as separate parameters
- Add return value to Across
- Add return value to Down
- Check if the grid, at the (new) coordinates == “F”
- ..if true, Call EatFood
Show text version of question
Question 6
Part (c)
(ii)
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 ..
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
- one new food ('F') is randomly generated and added to the grid.
20 animals)
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
- Place animal at that random
- Initialise the animal’s score to 0.
- Delete the food.
- Increase the score of the animal that
- Call the Constructor method of
- Call the
- Moves the animal to the new space.
- If there is food in the new position,
Constructor() between 0 and 39.
position.
called the method. EatFood() • Call the GenerateFood method of the Desert class.
the Animal class.
GenerateChangeInCoordinate method for each coordinate (across or down number) of the animal’s Move() 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
(ii)
The Move method uses the GenerateChangeInCoordinate function to calculate the
new Across and Down values for an animal. If there is food in the new position in the grid, the animal eats the food.
Write program code for the Move method.
Programming language .....................................................................................................
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[4]
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
