Question 7

OCR Computer Science June 2019 Paper 2A level40 marks

On the specification

(a)(i)
2.1 Elements of computational thinking
(a)(ii)
2.1 Elements of computational thinking
(a)(iii)
2.1 Elements of computational thinking
(b)(i)
2.2 Problem solving and programming
(b)(ii)
2.2 Problem solving and programming
(b)(iii)
2.2 Problem solving and programming
(b)(iv)
2.2 Problem solving and programming
(b)(v)
2.2 Problem solving and programming2.3 Algorithms
Question text

7 A program is needed to plan the layout of a garden. The program will allow the user to create an image of the garden, for example: Pear Apple Flower bed tree tree Path Patio Pear Vegetable bed tree (a) The programmer will use abstraction to produce the program interface to represent the garden. (i) Give two different examples of how abstraction has been used to produce the layout of the garden. 1 2 [2] (ii) Explain the need for abstraction in the production of this program. [3] (iii) The user needs to input data into the program to set up their garden layout. Identify three pieces of data that the user may input into this program. 1 2 3 [3] (b) The program is to be built using object oriented programming. All items that can be added to the garden are declared as instances of the class GardenItem. The class has the following attributes: Attribute Description Example itemName The name of the item Flowerbed length The length of the item in metres 2 width The width of the item in metres 1 (i) The constructor method sets the attributes to values that are passed as parameters. Write pseudocode or program code to declare the class GardenItem and its constructor. All attributes should be private and initialised through the constructor (e.g. daisies = new GardenItem("Flowerbed",2,1) ). [4] (ii) The trees in the garden layouts are defined by the class Tree. This class inherits from GardenItem. The class Tree has the additional attributes: height, sun, shade. If sun is true then the tree can grow in full sun, if it is false then it cannot. If shade is true then the tree can grow in full shade, if it is false then it cannot. The length and width of a tree are the same. Only one value for these measurements is passed to the constructor. Write an algorithm, using pseudocode or program code, to declare the class Tree. Declare all attributes as private. [5] (iii) The Common Oak is a type of tree. It has a maximum height, length and width of 40m. It can grow in sun and shade. Write a statement, using pseudocode or program code, to declare an instance of tree for the Common Oak. Give the object the identifier firstTree. [4] (iv) The classes GardenItem and Tree use get and set methods to access and alter their private attributes. Write the get method getItemName and set method setItemName for class GardenItem. The set method takes the new value as a parameter. [4] (v) The trees in the garden layouts are stored in a 1-dimensional array, treeArray. The array can store a maximum of 1000 items. The array has global scope. A procedure, findTree, takes as parameters: • The maximum height of a tree • The maximum width of a tree • Whether the tree can live in full sun • Whether the tree can live in full shade. It searches the array, treeArray, for all trees that do not exceed the maximum height and width, and that can grow in the conditions available. If there are no suitable trees, a suitable message is output. It outputs the name and details of the trees found in an appropriate message. Call the get methods, getItemName, getHeight, getWidth, getSun, getShade, to access the attributes. Write, using pseudocode or program code, the procedure findTree. [6] (c)* The programmer is designing the program to make use of caching and re-useable components. Explain and evaluate the use of caching and re-useable components in the design of the garden program. [9]