M.T paper 4
M.T paper 4
2 hours 30 minutes
evidence.doc
INSTRUCTIONS
● Carry out every instruction in each task.
● Save your work using the file names given in the task as and when instructed.
● You must not have access to either the internet or any email system during this examination.
● You must save your work in the evidence document as stated in the tasks. If work is not saved in the
evidence document, you will not receive marks for that task.
● You must use a high‑level programming language from this list:
Java (console mode)
Python (console mode)
Visual Basic (console mode)
● A mark of zero will be awarded if a programming language other than those listed here is used.
INFORMATION
● The total mark for this paper is 75.
● The number of marks for each question or part question is shown in brackets [ ].
DC (SL) 329378/3
© UCLES 2024 [Turn over
2
1 A program reads data from a file and searches for specific data.
(a) The main program needs to read 25 integer data items from the text file Data.txt
into a local 1D array, DataArray
Copy and paste the program code into part 1(a)(i) in the evidence document
[1]
(ii) Amend the main program to read the contents of Data.txt into DataArray
Copy and paste the program code into part 1(a)(ii) in the evidence document.
[4]
(b) (i) The procedure PrintArray() takes an integer array as a parameter and outputs the
contents of the array in the order they are stored.
10 4 5 13 25
Copy and paste the program code into part 1(b)(i) in the evidence document.
[3]
3
(ii) Amend the main program to output the contents of DataArray using the procedure
PrintArray()
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[1]
Copy and paste the screenshot into part 1(b)(iii) in the evidence document.
[1]
Copy and paste the program code into part 1(c) in the evidence document.
[3]
4
• prompt the user to input a whole number between 0 and 100 inclusive
• read and validate the input from the user
• call LinearSearch() with DataArray and the validated input value
• output the result in the format: The number 7 is found 2 times.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[4]
Copy and paste the screenshot into part 1(d)(ii) in the evidence document
[1]
5
The user can enter their requirements for a tree and a suitable tree will be selected.
Tree
MaxHeight : INTEGER each year stores the maximum height in cm that the tree will
grow
MaxWidth : INTEGER
stores the maximum width in cm that the tree will grow stores
Evergreen : STRING whether the tree keeps its
(a) (i) Write program code to declare the class Tree and its constructor.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
Copy and paste the program code into part 2(a)(ii) in the evidence document.
[3]
Beech,30,400,200,No
7
The tree is a Beech. It can grow 30cm each year. It has a maximum height of 400cm. It has a
maximum width of 200cm. It is not evergreen (it loses its leaves).
Copy and paste the program code into part 2(b) in the evidence document.
[7]
(c) The procedure PrintTrees() takes a Tree object as a parameter and outputs the tree’s
name, height growth each year, maximum height, maximum width and whether it is evergreen.
TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It does not lose its leaves.
TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It loses its leaves each year.
Copy and paste the program code into part 2(c) in the evidence document.
[4]
(d) The main program calls ReadData(), stores the return value and calls PrintTrees() with
the first object in the returned array.
Copy and paste the program code into part 2(d)(i) in the evidence document.
[2]
(ii) Test your program.
Copy and paste the screenshot into part 2(d)(ii) in the evidence document.
[1]
The procedure prompts the user to input their requirements for a tree.
• 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 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.
Copy and paste the program code into part 2(e)(i) in the evidence document.
[6]
(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
• 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 40cm when bought. The tree
will take 12 years to reach its maximum height of 400cm.
10
Copy and paste the program code into part 2(e)(ii) in the evidence document.
[2]
11
The class Character stores data about the characters. Each character has a name, a current
X (horizontal) position and a current Y (vertical) position.
SetYPosition()
adds the parameter to the Y position
validates that the new Y position is between 0
and 10000 inclusive
Move()
takes a direction as a parameter and calls
either SetXPosition or SetYPosition
with an integer value
(a) (i) Write program code to declare the class Character and its constructor.
Copy and paste the program code into part 3(a)(i) in the evidence document.
[4]
(ii) The get methods GetXPosition() and GetYPosition() each return the
relevant
attribute. Write program code for the get methods.
Copy and paste the program code into part 3(a)(ii) in the evidence document.
[3]
(iii) The set methods SetXPosition() and SetYPosition() each take a value as a parameter
and add this to the current X or Y position.
Copy and paste the program code into part 3(a)(iii) in the evidence document
[4]
13
(iv) The method Move() takes a string parameter: "up", "down", "left" or
"right". The table shows the change each direction will make to the X or Y position.
up Y position + 10
down Y position - 10
left X position + 10
right X position - 10
Copy and paste the program code into part 3(a)(iv) in the evidence document.
[4]
(b) Write program code to declare a new instance of Character with the identifier Jack.
The starting X position is 50 and the starting Y position is 50, the character’s name is Jack.
Copy and paste the program code into part 3(b) in the evidence document.
[2]
14
BikeCharacter
(i) Write program code to declare the class BikeCharacter and its constructor.
Do not declare the other method.
Use your programming language’s appropriate constructor.
If you are writing in Python, include attribute declarations using comments.
Copy and paste the program code into part 3(c)(i) in the evidence document
[3]
(ii) The method Move() overrides the method from the parent class. The table shows the
change each direction will make to the X or Y position.
up Y position + 20
down Y position - 20
left X position + 20
right X position - 20
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[2]
(d) Write program code to declare a new instance of BikeCharacter with the identifier Karla.
The starting X position is 100, the starting Y position is 50 and the character’s name is Karla.
Copy and paste the program code into part 3(d) in the evidence document.
[1]
• take as input which of the two characters the user would like to move
• take as input the direction the user would like the character to move
• call the appropriate method to move the character
• output the character’s new X and Y position in an appropriate format, for example:
"Karla's new position is X = 100 Y = 200"
Copy and paste the program code into part 3(e)(i) in the evidence document.
[5]