Past paper – A Level Computer Science (9618)

Cambridge International AS & A Level · 9618

Computer Science · Paper 43

Oct/Nov 2024 · 9618/43/O/N/24

Questions3
Marks75
TypeWritten

Answer on paper, open each mark scheme and give yourself marks, then open the Summary.

0 / 0Answer a question to start your score.
Saved 0
Advertisement
1
9618/43/O/N/24 · Question 1Oct/Nov 2024Paper 4322 marks
Loading question…
Question text

1
A program sorts string data using different sorting methods.
(a) The text file Data.txt stores string data items. Each data item is on a new line in the text
file.
The function ReadData():
•
has a local array of strings that can store 45 items
•
reads each line of data and stores it in the array
•
returns the array.
Write program code for the function ReadData().
Save your program as Question1_N24.
Copy and paste the program code into part 1(a) in the evidence document.
[6]
(b) The function FormatArray() takes an array of strings as a parameter. It concatenates the
contents of the array into one string with a space between each array element. The function
returns the concatenated string.
Write program code for FormatArray().
(i)
Save your program.
Copy and paste the program code into part 1(b)(i) in the evidence document.
[2]
(ii)
The main program:
•
calls ReadData() and stores the returned array
•
calls FormatArray() with the returned array and outputs the returned string.
Write program code for the main program.
Save your program.
Copy and paste the program code into part 1(b)(ii) in the evidence document.
[3]
(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 CompareStrings():
•
takes two strings as parameters
•
compares each string, one character at a time, to identify which string comes first
alphabetically. If the first two characters are the same, the second character of each
string is compared. This continues until the two characters are different.
The function:
•
returns 1 if the first parameter comes before the second alphabetically
•
returns 2 if the second parameter comes before the first alphabetically.
Write program code for CompareStrings().
Assume that all strings are in lower case.
Assume that a difference between two strings will always be identified before the end of one
string is reached.
Do not use an in-built string comparison function.
The strings must be compared one character at a time.
Save your program.
Copy and paste the program code into part 1(c) in the evidence document.
[4]
(d) The function Bubble() takes an array of strings as a parameter and sorts the data into
ascending alphabetical order, using a bubble sort. The bubble sort uses CompareStrings()
to compare each string.
The function returns the sorted list.
Write program code for Bubble().
(i)
Save your program.
Copy and paste the program code into part 1(d)(i) in the evidence document.
[3]
(ii)
Write program code to amend the main program to:
•
call Bubble() with the unsorted array as a parameter
•
call FormatArray() with the sorted array and output the returned string.
Save your program.
Copy and paste the program code into part 1(d)(ii) in the evidence document.
[2]
(iii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 1(d)(iii) in the evidence document.
[1]

2
9618/43/O/N/24 · Question 2Oct/Nov 2024Paper 4334 marks
Loading question…
Question text

2
A computer program is designed to simulate horses doing show jumping. In show jumping, horses
jump over obstacles called fences. A horse successfully jumps a fence if it does not knock the
fence down.
The program is written using Object-Oriented Programming (OOP).
The class Horse stores data about the horses.
Horse
Name : STRING
stores the name given to the horse
MaxFenceHeight : INTEGER
stores the maximum height in cm that the horse can
jump, for example 132
PercentageSuccess : INTEGER
stores the percentage chance of a horse not knocking
down a fence, for example 70 represents a 70% chance
of jumping a fence successfully
initialises Name, MaxFenceHeight and
Constructor()
PercentageSuccess to its parameter values
GetName()
returns the name of the horse
GetMaxFenceHeight()
returns the maximum height the horse can jump
Success()
calculates and returns the percentage chance of a horse
successfully jumping a specific fence
Write program code to declare the class Horse and its constructor.
(a) (i)
Do not declare the other methods.
Use your programming language’s appropriate constructor.
All attributes must be private. If you are writing in Python, include attribute declarations
using comments.
Save your program as Question2_N24.
Copy and paste the program code into part 2(a)(i) in the evidence document.
[4]
The get methods GetName() and GetMaxFenceHeight() each return the relevant
(ii)
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 array Horses stores objects of type Horse.
(i)
The program has two horses:
•
The horse named ‘Beauty’ can jump a maximum height of 150 cm and has a success
percentage rate of 72%.
•
The horse named ‘Jet’ can jump a maximum height of 160 cm and has a success
percentage rate of 65%.
Write program code to:
•
declare the array, Horses, local to the main program with space for two Horse
objects
•
store the two horses described in the array
•
output the name of both Horse objects from the array.
Save your program.
Copy and paste the program code into part 2(b)(i) in the evidence document.
[5]
(ii)
Test your program.
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 2(b)(ii) in the evidence document.
[1]
(c) The class Fence stores data about the fences. Each fence has a height in cm and a risk
number.
The risk is a whole number between 1 and 5 inclusive. A risk of 1 means the fence is the
easiest type to jump. A risk of 5 means the fence is the hardest type to jump.
Fence
Height : INTEGER
stores the height of the fence in cm
the height is between 70 and 180 inclusive
Risk : INTEGER
stores the risk as a whole number between 1 and 5
inclusive
initialises Height and Risk to its parameter values
Constructor()
GetHeight()
returns the height of the fence
GetRisk()
returns the risk of the fence
Write program code to declare the class Fence, its constructor and get methods.
(i)
Use your programming language’s appropriate constructor.
All attributes must be private.
If you are writing in Python, include attribute declarations using comments.
Save your program.
Copy and paste the program code into part 2(c)(i) in the evidence document.
[4]
The array Course stores four Fence objects. The user inputs the height and risk for
(ii)
each fence, and these are validated before each fence is created.
Amend the main program to:
•
declare the local array Course
•
take as input the data for four fences from the user
•
loop the input until both the height and risk are valid for each fence
•
create an instance of Fence for each of the four valid fences and store each
instance in the array.
Save your program.
Copy and paste the program code into part 2(c)(ii) in the evidence document.
[5]
(d) The chance of a horse jumping a fence without knocking it down is calculated as follows.
If the height of the fence is more than the maxi

3
9618/43/O/N/24 · Question 3Oct/Nov 2024Paper 4319 marks
Loading question…
Question text

3
A linked list stores positive integer data in a 2D array. The first dimension of the array stores the
integer data. The second dimension of the array stores the pointer to the next node in the linked
list.
A linked list node with no data is initialised with the integer –1. These nodes are linked together as
an empty list. A pointer of –1 identifies that node as the last node.
The linked list can store 20 nodes.
The global 2D array LinkedList stores the linked list.
LinkedList is initialised as an empty list. The data in each node is initialised to –1. Each node’s
pointer stores the index of the next node. The last node stores the pointer value –1, which indicates
it is the last node.
The global variable FirstEmpty stores the index of the first element in the empty list. This is the
first node in the empty linked list when it is initialised, which is index 0.
The global variable FirstNode stores the index of the first element in the linked list. There is no
data in the linked list when it is initialised, so FirstNode is initialised to –1.
This diagram shows the content of the initialised array.
FirstEmpty = 0
FirstNode = –1
Index
Data
Pointer
0
-1
1
1
-1
2
2
-1
3
3
-1
4
4
-1
5
19
-1
-1
(a) Write program code for the main program to declare and initialise LinkedList, FirstNode
and FirstEmpty.
Save your program as Question3_N24.
Copy and paste the program code into part 3(a) in the evidence document.
[2]
(b) The procedure InsertData() takes five positive integers as input from the user and inserts
these into the linked list.
Each data item is inserted at the front of the linked list.
The table shows the steps to follow depending on the state of the linked list:
Linked list state
Steps
insert the data in the index pointed to by FirstEmpty
change the pointer to the index pointed to by FirstNode
not full
change the values of FirstNode and FirstEmpty
full
end the procedure
Any node that is at the end of the linked list has a pointer of –1.
Write program code for InsertData().
Save your program.
Copy and paste the program code into part 3(b) in the evidence document.
[6]
(c) The procedure OutputLinkedList() outputs the data in the linked list in order by following
the pointers from FirstNode.
Write program code for OutputLinkedList().
(i)
Save your program.
Copy and paste the program code into part 3(c)(i) in the evidence document.
[2]
Amend the main program to call InsertData() and then OutputLinkedList().
(ii)
Save your program.
Copy and paste the program code into part 3(c)(ii) in the evidence document.
[1]
(iii)
Test your program with the test data:
5
1
2
3
8
Take a screenshot of the output.
Save your program.
Copy and paste the screenshot into part 3(c)(iii) in the evidence document.
[1]
(d) The procedure RemoveData() removes a node from the linked list.
The procedure takes the data item to be removed from the linked list as a parameter.
The procedure checks each node in the linked list, starting with the node FirstNode, until it
finds the node to be removed. This node is added to the empty list, and pointers are changed
as appropriate. The procedure only removes the first occurrence of the parameter.
Assume that the data item being removed is in the linked list.
Write program code for RemoveData().
(i)
Save your program.
Copy and paste the program code into part 3(d)(i) in the evidence document.
[5]
(ii)
Amend the main program to:
•
call RemoveData() with the parameter 5
•
output the word "After"
•
call OutputLinkedList().
Save your program.
Copy and paste the program code into part 3(d)(ii) in the evidence document.
[1]
(iii)
Test your program with both sets of given test data:
Test data set 1:
5
6
8
9
5
Test data set 2:
10
7
8
5
6
Take a screenshot of each output.
Save your program.
Copy and paste the screenshot(s) into part 3(d)(iii) in the evidence document.
[1]
Permission to reproduce items where third-party owned material protected by copyr

Advertisement