Past-paper question · 2024 May-June · Paper 43 · Q4(e)(ii)

Question 4(e)(ii) 2024 · May-June · Paper 43 · 14 marks

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

The answer for this question is in the official mark scheme: open the mark scheme.

Mark scheme 9618_s24_ms_43.pdf →

Show text version of question

Question 4

Part (e)

(ii)

Question 4

Question 1

Question 2

Take a screenshot of the output(s).

Save your program.

Copy and paste the screenshot into part 1(d)(iii) in the evidence document.

[1]

Part (e)

The function BinarySearch():

  • takes the integer parameter DataToFind to search for in the array
  • performs an iterative binary search on the array DataStored
  • returns the index where DataToFind is found in DataStored. If DataToFind is not

found, the function returns −1.

(i)

Write program code for the iterative function BinarySearch().

Save your program.

Copy and paste the program code into part 1(e)(i) in the evidence document.

[6]

(ii)

Write program code to amend the main program to:

  • take a number as input from the user
  • call BinarySearch() with the number input
  • output the value returned from the function call as its parameter.

Save your program.

Copy and paste the program code into part 1(e)(ii) in the evidence document.

[3]

Question 5

(iii)

Test your program twice with the following inputs:

Test 1: 5 1 6 2 8 10 2

Test 2: 5 1 6 2 8 10 7

Take a screenshot of the output(s).

Save your program.

Copy and paste the screenshot into part 1(e)(iii) in the evidence document.

[2]

Question 6

2 A computer program will store data about trees.

The user can enter their requirements for a tree and a suitable tree will be selected.

The program is written using object‑oriented programming.

The class Tree stores data about the trees.

Tree TreeName : STRING stores the name of the tree

HeightGrowth : INTEGER stores the number of cm the tree will grow each year

MaxHeight : INTEGER stores the maximum height in cm that the tree will grow

MaxWidth : INTEGER stores the maximum width in cm that the tree will grow

Evergreen : STRING stores whether the tree keeps its leaves as "Yes", or loses its leaves as "No" Constructor() initialises TreeName, HeightGrowth, MaxHeight, MaxWidth and Evergreen to its parameter values

GetTreeName() returns the name of the tree

GetGrowth() returns the number of cm the tree will grow each year

GetMaxHeight() returns the maximum height in cm that the tree will grow

GetMaxWidth() returns the maximum width in cm that the tree will grow

GetEvergreen() returns whether the tree keeps its leaves or loses its leaves The procedure ChooseTree() takes an array of Tree objects as a parameter.

The procedure prompts the user to input their requirements for a tree. The user needs to enter:

  • the maximum height the tree can be in cm
  • the maximum width the tree can be in cm
  • whether they want the tree to be evergreen, or not evergreen.
A
tree meets the requirements if:
  • the tree’s maximum height is not more than the user’s input

and

  • the tree’s maximum width is not more than the user’s input

and

  • the tree matches their evergreen input.

The procedure creates a new array of all the Tree objects that meet all the requirements.

The procedure calls PrintTrees() for each Tree object that meets all the requirements. If there are no trees that meet all the requirements, a suitable message is output.

(ii)

The procedure ChooseTree() needs amending. After the procedure has output the list

of trees that meet all the requirements, the procedure needs to:

  • take as input the name of one of the trees that the user would like to buy from those
  • that meet all the requirements

  • take as input the height of the tree in cm when it is bought
  • calculate and output how many years it will take the tree to grow to its maximum

height.

For example, the user inputs the tree, Beech. The tree’s height is 40 cm when bought. The tree will take 12 years to reach its maximum height of 400 cm.

Write program code to amend ChooseTree().

Save your program.

Copy and paste the program code into part 2(e)(ii) in the evidence document.

[2]

Question 10

Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Programming basics

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 9618_s24_qp_43.pdf

Keep practising this topic