A Level Computer Science 9618 Paper 42, May/June 2025

Question paper and mark scheme75 marks3 questions

Solve it on ExamPal

Practise

Untimed. Write on the paper and check as you go.

Start

Exam

Timed, with a clock you set, like sitting the real paper.

Start

Opens full screen.

Opening the question paper

Read as textThe questions and the mark scheme as plain text. Easier to read on a phone.

Question paper

9618/42 · May/June 2025

Download PDF
1

A program reads data from a text file and stores it in a stack. The stack Stack is stored as a 1D array of up to 20 elements. The pointer TopOfStack stores the index of the last element stored in the stack.

a

Stack is a global array of strings with all elements initialised to "-1" TopOfStack is a global variable initialised to –1 Write program code to declare and initialise Stack and TopOfStack Save your program as Question1_J25. Copy and paste the program code into part 1(a) in the evidence document.

[2]
b

The function Push() takes a string parameter and attempts to store it on the stack. The function returns –1 if the stack is full. The function returns 1 if the parameter is successfully pushed onto the stack. Write program code for Push() Save your program. Copy and paste the program code into part 1(b) in the evidence document.

[4]
c

The function Pop() returns the next item from the stack. The function returns "–1" if the stack is empty. Write program code for Pop() Save your program. Copy and paste the program code into part 1(c) in the evidence document.

[4]
d

The text file StackData.txt stores numbers and mathematical operators. Each number and operator are on a new line in the text file. The mathematical operators used in this program are:

mathematical operatormeaning
+addition
–subtraction
/division
*multiplication
^power of

The procedure ReadData(): • takes a string filename as a parameter • opens the file and reads in each line of data • uses the Push() function to insert each line of data onto the stack • outputs "Stack full" if any data cannot be stored on the stack because the stack is full • uses exception handling when opening and reading from the text file. The procedure needs to work for a file that contains an unknown number of lines. Write program code for ReadData() Save your program. Copy and paste the program code into part 1(d) in the evidence document.

[6]
e

The values stored in the stack are used to perform mathematical operations. A total is initialised to the first value in the stack. The first value in the stack will always be a number. The next value will be a mathematical operator and the next value will be the number to apply to the calculation. This is repeated until there are no values left in the stack. There will always be a number following a mathematical operator. For example, the contents of a stack are:

10
+
3
–
2

⟵ TopOfStack The total is initialised to the first value in the stack: 10 total = 10 The next two values are: + 3 total = 10 + 3 = 13 The next two values are: – 2 total = 13 – 2 = 11 The final total is 11 and this is returned. Write program code for the function Calculate() to: • take each value from the stack • calculate and return the final total. Save your program. Copy and paste the program code into part 1(e) in the evidence document.

[7]
f(i)

Write program code to extend the main program to: • take a filename as input from the user • call ReadData() with the input filename • call Calculate() • output the final total. Save your program. Copy and paste the program code into part 1(f)(i) in the evidence document.

[2]
f(ii)

Test your program twice with the file names: StackData.txt SecondStack.txt Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 1(f)(ii) in the evidence document.

[2]
2

A program stores data in a 1D array of records, HashTable. The array has space for 200 records. Each data item is stored in a specific index of the array that is calculated using an algorithm. The index is calculated from the key field using the formula: Key MOD 200 If two key fields generate the same index, there is a collision. Any records that have a collision are stored in a second array, Spare. This array has space for 100 records. When a collision is detected, the record is stored in the next free space in Spare.

a

The pseudocode record format is: TYPE NewRecord DECLARE Key : INTEGER DECLARE Item1 : INTEGER DECLARE Item2 : INTEGER ENDTYPE Write program code to declare the record type NewRecord If your chosen programming language does not support record formats, a class can be used instead. Save your program as Question2_J25. Copy and paste the program code into part 2(a) in the evidence document.

[2]
b(i)

Write program code to declare the global arrays HashTable and Spare Save your program. Copy and paste the program code into part 2(b)(i) in the evidence document.

[1]
b(ii)

An empty record has the integer –1 stored in each field. The procedure Initialise() stores an empty record in each element in HashTable and Spare Write program code for Initialise() Save your program. Copy and paste the program code into part 2(b)(ii) in the evidence document.

[2]
c

The hash value is calculated from the key field using the formula: Key MOD 200 The function CalculateHash() takes a key field as a parameter and calculates and returns the hash value for the key field. Write program code for CalculateHash() Save your program. Copy and paste the program code into part 2(c) in the evidence document.

[2]
d

The procedure InsertIntoHash(): • takes a record of type NewRecord as a parameter • uses CalculateHash() to calculate the hash value for the key field in the record • checks if the hash value index in HashTable currently stores an empty record ○ if the index stores an empty record, store the parameter in this index ○ if the index does not store an empty record, store the parameter in Spare You can assume there will always be enough space in Spare to store any collisions. Write program code for InsertIntoHash() Save your program. Copy and paste the program code into part 2(d) in the evidence document.

[6]
e

The text file HashData.txt stores up to 200 rows of data to be stored into the hash table. Each row contains three integer numbers separated by commas. The first number is the key field, the second number is item 1 and the third number is item 2. For example: The first row in the text file contains: 646, 12, 568 The key field is 646, item 1 is 12 and item 2 is 568 The procedure CreateHashTable(): • opens the file HashData.txt • creates a record for each row of data in the file • calls InsertIntoHash() with each record. Write program code for CreateHashTable() Save your program. Copy and paste the program code into part 2(e) in the evidence document.

[5]
f(i)

The procedure PrintSpare() outputs the key field of each element in the array Spare that does not contain an empty record. Write program code for PrintSpare() Save your program. Copy and paste the program code into part 2(f)(i) in the evidence document.

[2]
f(ii)

The main program should call the procedure to initialise the arrays, call the procedure to create the hash table and then call the procedure to output the contents of the array Spare Write program code for the main program. Save your program. Copy and paste the program code into part 2(f)(ii) in the evidence document.

[1]
f(iii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 2(f)(iii) in the evidence document.

[1]
3

A program stores data about animals using Object-Oriented Programming (OOP). The class Animal stores the data about animals.

Animal
Name : Stringstores the name of the animal
Sound : Stringstores the sound the animal makes
Size : Integerstores the size of the animal as an integer between 1 (smallest) and 10 (largest)
Intelligence : Integerstores the intelligence of the animal as an integer between 1 (least) and 10 (most)
Constructor()initialises all attributes to its parameter values
Description()returns a string message that contains the data from the attributes
a(i)

Write program code to declare the class Animal and its constructor. Do not declare the other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments. Save your program as Question3_J25. Copy and paste the program code into part 3(a)(i) in the evidence document.

[4]
a(ii)

The method Description() creates and returns a string of the animal’s data in the format: "The animal's name is " <Name> ", it makes a " <Sound> ", its size is " <Size> " and its intelligence level is " <Intelligence> For example: The animal's name is Teddy, it makes a Bark, its size is 4 and its intelligence level is 6 Write program code for Description() Save your program. Copy and paste the program code into part 3(a)(ii) in the evidence document.

[3]
b(i)

The class Parrot inherits from the class Animal Parrot inherits the attributes from Animal and overrides the Description() method. The additional attributes and methods in the class Parrot are:

Parrot
WingSpan : Integerthe width of the parrot's wings to the nearest cm
NumberWords : Integerthe number of words the parrot can speak
Constructor()calls the parent constructor using its parameter values; initialises WingSpan and NumberWords to its parameter values
ChangeNumberWords()takes an integer parameter and adds this to the number currently in NumberWords

Write program code to declare the class Parrot, its constructor and the method ChangeNumberWords() Use your programming language 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(b)(i) in the evidence document.

[4]
b(ii)

The method Description() in the class Parrot creates and returns a string of the animal’s data in the format: "The animal's name is " <Name> ", it makes a " <Sound> ", its size is " <Size> " and its intelligence level is " <Intelligence> ". It has a wingspan of " <WingSpan> "cm and can say " <NumberWords> " words." For example: The animal's name is Chewie, it makes a Squawk, its size is 1 and its intelligence level is 10. It has a wingspan of 30cm and can say 29 words. Write program code for Description() Save your program. Copy and paste the program code into part 3(b)(ii) in the evidence document.

[2]
c(i)

The class Wolf inherits from the class Animal Wolf inherits the attributes from Animal and overrides the Description() method. The additional attributes and methods in the class Wolf are:

Wolf
TerritorySize : Integerstores the size of the area where the wolf lives, to the nearest square mile
Constructor()calls the parent constructor using its parameter values; initialises TerritorySize to its parameter value
SetTerritorySize()takes an integer parameter and adds this to the number currently in TerritorySize

Write program code to declare the class Wolf, its constructor and the method SetTerritorySize() Use your programming language 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.

[4]
c(ii)

The method Description() in the class Wolf creates and returns a string of the animal’s data in the format: "The animal's name is " <Name> ", it makes a " <Sound> ", its size is " <Size> " and its intelligence level is " <Intelligence> ". Its territory is " <TerritorySize> " square miles." For example: The animal's name is Nighteyes, it makes a Howl, its size is 8 and its intelligence level is 7. Its territory is 100 square miles. Write program code for Description() Save your program. Copy and paste the program code into part 3(c)(ii) in the evidence document.

[2]
d(i)

The main program declares instances of the classes for three animals: • A parrot with the name ‘Chewie’; it makes a ‘Squawk’ sound. Its size is 1, intelligence is 10, wingspan is 30cm and it can say 29 words. • A wolf with the name ‘Nighteyes’; it makes a ‘Howl’ sound. Its size is 8, intelligence is 7 and its territory is 100 square miles. • An animal that is a horse with the name ‘Copper’; it makes a ‘Neigh’ sound. Its size is 10 and its intelligence is 6. Write program code for the main program. Save your program. Copy and paste the program code into part 3(d)(i) in the evidence document.

[2]
d(ii)

The main program also needs to: • decrease the territory for the wolf Nighteyes by 20 square miles • increase the number of words the parrot Chewie can say by 2 words • output the description for all three animals. Write program code to extend the main program. Save your program. Copy and paste the program code into part 3(d)(ii) in the evidence document.

[3]
d(iii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 3(d)(iii) in the evidence document.

[2]

Mark scheme

9618/42 · May/June 2025

Download PDF

1a · 2 marks

  • 1 mark

    (Global) Stack as 1D array (of strings) with 20 elements initialised to string "–1"

  • 1 mark

    (Global) TopOfStack initialised to –1

1b · 4 marks

  • 1 mark

    Push function header (and end where appropriate) taking one (string) parameter

  • 1 mark

    Checking if stack is full and returning integer –1

  • 1 mark

    (Otherwise) Incrementing TopOfStack

  • 1 mark

    Storing parameter in the incremented the stack at TopOfStack and returning integer 1

1c · 4 marks

  • 1 mark

    Function header (and end where appropriate) and returning a value in all cases.

  • 1 mark

    Checking if stack is empty and returning string "–1"

  • 1 mark

    (Otherwise) Decrementing TopOfStack

  • 1 mark

    Returning element in stack at TopOfStack before TopOfStack is decremented

1d · 6 marks

  • 1 mark

    Procedure header (and end where appropriate) taking one (string) parameter

  • 1 mark

    Opening the file with the filename parameter and closing the file in an appropriate place

  • 1 mark

    Looping through to end of file and reading in each line ...

  • 1 mark

    … calling Push() once with each read in value …

  • 1 mark

    … if any return value from Push() is integer –1 outputting "Stack full"

  • 1 mark

    Exception handling for opening and reading from file with appropriate catch and output

1e · 7 marks

  • 1 mark

    Calculate() function header (and end where appropriate)

  • 1 mark

    Looping until the stack is empty

  • 1 mark

    Calling Pop() repeatedly within loop and storing/using return value

  • 1 mark

    … working out if return value from Pop() call is an operator or a number / alternating between operator and number

  • 1 mark

    Select to determine if the operator is +, -, /, * or ^ and attempt the matching calculation

  • 1 mark

    … performing correct calculation using operator, number

  • 1 mark

    … updating total from previous loops and returning this final value

1f(i) · 2 marks

  • 1 mark

    Taking a filename as input and calling ReadData() with input

  • 1 mark

    Calling Calculate() and outputting the return value

1f(ii) · 2 marks

  • 1 mark

    screenshot showing input of StackData.txt and output of 131

  • 1 mark

    screenshot showing input of SecondStack.txt and output of 320

2a · 2 marks

  • 1 mark

    Record/class NewRecord declared

  • 1 mark

    3 variables within structure (all integer)

2b(i) · 1 mark

  • 1 mark

    HashTable (200 records) and Spare (100 records) declared as (global) arrays

2b(ii) · 2 marks

  • 1 mark

    Procedure Initialise() header (and close where appropriate) that initialises all elements in both arrays …

  • 1 mark

    … to an empty record with –1 in each of the 3 fields/elements

2c · 2 marks

  • 1 mark

    Function header (and close where appropriate), taking one (integer) parameter and returning the calculated value

  • 1 mark

    Calculation of parameter MOD 200

2d · 6 marks

  • 1 mark

    Procedure header (and end where appropriate) taking one record as a parameter

  • 1 mark

    Calling CalculateHash() with key from parameter record and storing/using return value

  • 1 mark

    Checking if HashTable at return value from CalculateHash is empty record …

  • 1 mark

    … if it is empty, store parameter in location

  • 1 mark

    … otherwise, locating next free space in Spare …

  • 1 mark

    … and storing in that index only (i.e. not in all other free spaces)

2e · 5 marks

  • 1 mark

    Procedure header (and end where appropriate), opening and closing file HashData.txt

  • 1 mark

    Reading in all lines of data …

  • 1 mark

    … splitting each line by commas

  • 1 mark

    Creating record with correct values with each line read in from file

  • 1 mark

    Calling InsertIntoHash() with each record they have created

  • 1 mark

    Exception handling for opening and reading from file with appropriate catch and output.

2f(i) · 2 marks

  • 1 mark

    Procedure header (and end where appropriate) and looping through each element in Spare …

  • 1 mark

    … checking if record is empty and outputting key field if not empty

2f(ii) · 1 mark

  • 1 mark

    calling Initialise() then CreateHashTable() then PrintSpare()

2f(iii) · 1 mark

  • 1 mark

    output

3a(i) · 4 marks

  • 1 mark

    Class header (and end when appropriate)

  • 1 mark

    Four attributes with appropriate data types

  • 1 mark

    Constructor header (and end where appropriate) within class taking (min) 4 parameters …

  • 1 mark

    … assigning each parameter to its attribute

3a(ii) · 3 marks

  • 1 mark

    Description() method header (and end where appropriate) with no parameter

  • 1 mark

    Concatenating the attributes with the given message …

  • 1 mark

    … and returning the created message

3b(i) · 4 marks

  • 1 mark

    Class header (and end where appropriate) inherits from Animal

  • 1 mark

    Constructor header (and end where appropriate) taking 6 parameters within class and calling parent constructor with the four parameters …

  • 1 mark

    … WingSpan and NumberWords attributes defined with data types and parameters assigned within constructor

  • 1 mark

    ChangeNumberWords() method header (and end where appropriate) takes one parameter and adds parameter to attribute NumberWords

3b(ii) · 2 marks

  • 1 mark

    Description() method header (and end where appropriate) taking no parameters and overriding/overloads/extending/using parent method

  • 1 mark

    Concatenating and returning the correct string

3c(i) · 4 marks

  • 1 mark

    Class header (and end where appropriate) inherits from Animal

  • 1 mark

    Constructor header (and end where appropriate) taking 5 parameters within class and calling parent constructor with parameters

  • 1 mark

    Attribute Territory defined as int and parameter assigned within constructor

  • 1 mark

    SetTerritory() method header (and end) takes 1 parameter and adds parameter to attribute TerritorySize

3c(ii) · 2 marks

  • 1 mark

    Description() method header (and end where appropriate) taking no parameters and overriding/overloads/extending/using parent method

  • 1 mark

    Concatenating and return correct message

3d(i) · 2 marks

  • 1 mark

    1 correct instance created and stored in a suitable variable/structure

  • 1 mark

    2nd and 3rd correct instances created and stored in a suitable variable/structure

3d(ii) · 3 marks

  • 1 mark

    Calling SetTerritorySize(-20) for instance of Nighteyes

  • 1 mark

    Calling ChangeNumberWords(2) for instance of Chewie

  • 1 mark

    Calling Description() for all 3 animals (after any updates) and outputting return values

3d(iii) · 2 marks

  • 1 mark

    All three messages accurate with all relevant values

  • 1 mark

    … showing correctly updated territory for Nighteyes and words for Chewie

Questions

  1. 1
    Question 127 marks
    Mark scheme ›
  2. 2
    Question 222 marks
    Mark scheme ›
  3. 3
    Question 326 marks
    Mark scheme ›

More 9618 papers

Other papers from May/June 2025

Solve it on ExamPalStart