0% found this document useful (0 votes)
41 views

M.T paper 4

This document outlines the Cambridge International AS & A Level Computer Science Paper 4 Practical for May/June 2024, which consists of programming tasks to be completed in a high-level programming language. Candidates are instructed to follow specific guidelines for saving their work and are assessed on their ability to read data from files, implement functions and procedures, and utilize object-oriented programming concepts. The paper includes multiple programming tasks related to data handling, class creation, and user interaction, with a total mark of 75.

Uploaded by

Aleena Qayyum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

M.T paper 4

This document outlines the Cambridge International AS & A Level Computer Science Paper 4 Practical for May/June 2024, which consists of programming tasks to be completed in a high-level programming language. Candidates are instructed to follow specific guidelines for saving their work and are assessed on their ability to read data from files, implement functions and procedures, and utilize object-oriented programming concepts. The paper includes multiple programming tasks related to data handling, class creation, and user interaction, with a total mark of 75.

Uploaded by

Aleena Qayyum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Cambridge International AS & A Level

COMPUTER SCIENCE 9618/43


Paper 4 Practical May/June 2024

2 hours 30 minutes

You will need: Candidate source files (listed on page 2)


* 0 0 9 5 7 4 4 4 0 5 *

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 [ ].

This document has 16


5 pages. Any blank pages are indicated.

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

(i) Write program code to declare the local array DataArray

Save your program as Question1_MT.

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

Save your program.

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.

The items are printed on the same line, for example:

10 4 5 13 25

Write program code for the procedure PrintArray()

Save your program.

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()

Save your program.

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

[1]

(iii) Test your program.

Take a screenshot of the output.

Save your program.

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

[1]

(c) The function LinearSearch() :

• takes an integer array and integer search value as parameters


• counts and returns the number of times the search value is found in the array.

Write program code for the function LinearSearch()

Save your program.

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

[3]
4

(d) (i) Amend the main program to :

• 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.

Save your program.

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

[4]

(ii) Test your program by inputting the number 12.

Take a screenshot of the output.

Save your program.

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

[1]
5

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

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

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
6

(a) (i) Write program code to declare the class Tree and its constructor.

Do not declare the other methods.

Use the appropriate constructor for your programming language.

All attributes must be private.

If you are writing in Python, include attribute declarations using comments.

Save your program as Question2_MT.

Copy and paste the program code into part 2(a)(i) in the evidence document.

[4]

(ii) The get methods GetTreeName(), GetGrowth(), GetMaxHeight(),

GetMaxWidth() and GetEvergreen() each return the relevant attribute.

Write program code for the get methods.

Save your program.

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

[3]

(b) The text file Trees.txt stores data about 9 trees.

The data in the file is stored in the format:

Tree name,Height growth each year,Maximum height,Maximum width,Evergreen

For example, the first row of data is:

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).

The function ReadData():

• creates an array of type Tree


• reads the data from the file
• raises an exception if the file is not found
• creates a new object of type Tree for each tree in the file
• appends each object to the array
• returns the array.

Write program code for ReadData().

Save your program.

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.

The output message changes depending on whether it is evergreen.


If it is evergreen, it is in the format:

TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It does not lose its leaves.

If it is not evergreen, it is in the format:

TreeName has a maximum height MaxHeight a maximum width MaxWidth and grows
HeightGrowth cm a year. It loses its leaves each year.

Write program code for PrintTrees().


8

Save your program.

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.

(i) Write program code for the main program.

Save your program.

Copy and paste the program code into part 2(d)(i) in the evidence document.

[2]
(ii) Test your program.

Take a screenshot of the output(s).

Save your program.

Copy and paste the screenshot into part 2(d)(ii) in the evidence document.

[1]

(e) 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.
9

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.

(i) Write program code for ChooseTree().

Save your program.

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

• 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 40cm when bought. The tree
will take 12 years to reach its maximum height of 400cm.
10

Save your program.

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

[2]
11

3 A computer game is written using object-oriented programming.


The game has multiple characters that can move around the screen.

The class Character stores data about the characters. Each character has a name, a current
X (horizontal) position and a current Y (vertical) position.

(winter 2023 41)


Character

Name : STRING stores the name of the character as a string

XPosition : INTEGER stores the X position as an integer

YPosition : INTEGER stores the Y position as an integer

Constructor() initialises Name, XPosition and


YPosition to its parameter values

GetXPosition() returns the X position


GetYPosition() returns the Y position

adds the parameter to the X position


SetXPosition() validates that the new X position is between 0
and 10000 inclusive

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.

Do not declare the other methods.

Use your programming language’s appropriate constructor.

If you are writing in Python, include attribute declarations using comments.


12

Save your program as Question3_MT.

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.

Save your program.

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.

If the new value exceeds 10000, it is limited to 10000.


If the new value is below 0, it is limited to 0.

Write program code for the set methods.

Save your program.

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.

Use the appropriate method to change the position value.

Direction Value Change

up Y position + 10

down Y position - 10

left X position + 10

right X position - 10

Write program code for Move().

Save your program.

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.

Save your program.

Copy and paste the program code into part 3(b) in the evidence document.

[2]
14

(c) The class BikeCharacter inherits from the class Character.

BikeCharacter

Constructor() takes Name, XPosition and YPosition


as parameters calls its parent class
constructor with the appropriate values

overrides the method Move() from the


Move() parent class by changing either the X position
or the Y position by 20 instead of 10

(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.

Save your program.

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.

Direction Value Change

up Y position + 20

down Y position - 20

left X position + 20

right X position - 20

Write program code for Move().


15

Save your program.

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.

Save your program.

Copy and paste the program code into part 3(d) in the evidence document.

[1]

(e) (i) Write program code to:

• 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"

All inputs require appropriate prompts and must be validated.

Save your program.

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

[5]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy