Past-paper question · 2017 October-November · Paper 41 · Q6(d)

Question 6(d) 2017 · October-November · Paper 41 · 2 marks

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

Official answer for Question 6

Part (d)

Question 1

mark per bullet to max 3

Question 2

  • Pre-compiled
  • Collection of Code/modules/routines
  • Each module performs a specific purpose/task
  • Each module can be linked/imported into the program

Mark scheme 9608_w17_ms_41.pdf →

Show text version of question

Question 6

Part (d)

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

Part (d)

The programmer plans to add a graphic display to the program. The programmer will make

use of a program library.

Explain what is meant by a program library.

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

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

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

...............................................................................................................................................[2]

reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.

To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series.

Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.

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

Keep practising this topic