A Level Computer Science 9618 Paper 41, May/June 2024

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.

Papers open in

Opening the question paper

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

Question paper

9618/41 · May/June 2024

Download PDF
1

A program needs to take integer numbers as input, sort the numbers and then search for a specific number.

a

The integer numbers will be stored in the global 1D array, DataStored, with space for up to 20 integers. The global variable NumberItems stores the quantity of items the array contains. Write program code to declare DataStored and NumberItems. Save your program as Question1_J24. Copy and paste the program code into part 1(a) in the evidence document.

[1]
b

The procedure Initialise(): • prompts the user to input the quantity of numbers the user would like to enter • reads the input and validates it is between 1 and 20 (inclusive) • prompts the user to input each number and stores each number in DataStored. Write program code for Initialise(). Save your program. Copy and paste the program code into part 1(b) in the evidence document.

[5]
c(i)

The main program stores 0 in NumberItems, calls Initialise() and then outputs the contents of DataStored. Write program code for the main program. Save your program. Copy and paste the program code into part 1(c)(i) in the evidence document.

[2]
c(ii)

Test your program by inputting the following data in the order given: 30 5 3 9 4 1 2 Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 1(c)(ii) in the evidence document.

[2]
d(i)

The procedure BubbleSort() uses a bubble sort to sort the data in DataStored into ascending numerical order. Write program code for BubbleSort(). Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document.

[4]
d(ii)

Write program code to amend the main program to call BubbleSort() and then output the contents of DataStored. Save your program. Copy and paste the program code into part 1(d)(ii) in the evidence document.

[1]
d(iii)

Test your program by inputting the following data in the order given: 5 3 9 4 1 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]
e(i)

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

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_J24. Copy and paste the program code into part 2(a)(i) in the evidence document.

[4]
a(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 The tree is a Beech. It can grow 30 cm each year. It has a maximum height of 400 cm. It has a maximum width of 200 cm. 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(). Save your program. Copy and paste the program code into part 2(c) in the evidence document.

[4]
d(i)

The main program calls ReadData(), stores the return value and calls PrintTrees() with the first object in the returned array. 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]
d(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(i)

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. Write program code for ChooseTree(). Save your program. Copy and paste the program code into part 2(e)(i) in the evidence document.

[6]
e(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]
e(iii)

Write program code to amend the main program to call ChooseTrees(). Test your program with the following tree requirements: • a maximum height of 400 cm • a maximum width of 200 cm • a tree that is evergreen (does not lose its leaves). When asked for the tree selection, use the following data: • first tree name entered is ‘Blue Conifer’ • starting height is 100 cm. Take a screenshot of the outputs. Save your program. Copy and paste the screenshot into part 2(e)(iii) in the evidence document.

[2]
3

A program reads data from the user and stores the data that is valid in a linear queue. The queue is stored as a global 1D array, QueueData, of string values. The array needs space for 20 elements. The global variable QueueHead stores the index of the first element in the queue. The global variable QueueTail stores the index of the last element in the queue.

a

The main program initialises all the elements in QueueData to a suitable null value, QueueHead to −1 and QueueTail to −1. Write program code for the main program. Save your program as Question3_J24. Copy and paste the program code into part 3(a) in the evidence document.

[1]
b

The function Enqueue() takes the data to insert into the queue as a parameter. If the queue is not full, it inserts the parameter in the queue, updates the appropriate pointer(s) and returns TRUE. If the queue is full, it returns FALSE. Write program code for Enqueue(). Save your program. Copy and paste the program code into part 3(b) in the evidence document.

[4]
c

The function Dequeue() returns "false" if the queue is empty. If the queue is not empty, it returns the next item in the queue and updates the appropriate pointer(s). Write program code for Dequeue(). Save your program. Copy and paste the program code into part 3(c) in the evidence document.

[3]
d(i)

The string values to be stored in the queue are 7 characters long. The first 6 characters are digits and the 7th character is a check digit. The check digit is calculated from the first 6 digits using this algorithm: • multiply the digits in position 0, position 2 and position 4 by 1 • multiply the digits in position 1, position 3 and position 5 by 3 • calculate the sum of the products (add together the results from all of the multiplications) • divide the sum of the products by 10 and round the result down to the nearest integer to get the check digit • if the check digit equals 10 then it is replaced with 'X'. Example: Data is 954123 Character position: 0 1 2 3 4 5 Digit: 9 5 4 1 2 3 Multiplier: 1 3 1 3 1 3 Product: 9 15 4 3 2 9 Sum of products = 9 + 15 + 4 + 3 + 2 + 9 = 42 Divide sum of products by 10: 42 / 10 = 4 (rounded down) The check digit = 4. This is inserted into character position 6. The data including the check digit is: 9541234 A 7-character string is valid if the 7th character matches the check digit for that data. For example, the data 9541235 is invalid because the 7th character (5) does not match the check digit for 954123. The subroutine StoreItems() takes ten 7-character strings as input from the user and uses the check digit to validate each input. Each valid input has the check digit removed and is stored in the queue using Enqueue(). An appropriate message is output if the item is inserted. An appropriate message is output if the queue is already full. Invalid inputs are not stored in the queue. The subroutine counts and outputs the number of invalid items that were entered. StoreItems() can be a procedure or a function as appropriate. Write program code for StoreItems(). Save your program. Copy and paste the program code into part 3(d)(i) in the evidence document.

[6]
d(ii)

Write program code to amend the main program to: • call StoreItems() • call Dequeue() • output a suitable message if the queue was empty • output the returned value if the queue was not empty. Save your program. Copy and paste the program code into part 3(d)(ii) in the evidence document.

[1]
d(iii)

Test the program with the following inputs in the order given: 999999X 1251484 5500212 0033585 9845788 6666666 3258746 8111022 7568557 0012353 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/41 · May/June 2024

Download PDF

1a · 1 mark

  • 1 mark

    Declaration of (global) array with identifier DataStored (Integer and 20 spaces) and NumberItems (Integer)

1b · 5 marks

  • 1 mark

    Procedure heading (and close where appropriate) with no parameter.

  • 2 marks

    Prompt/output of suitable message to request the input of the quantity of numbers and reading in quantity of numbers and storing/using …

  • 2 marks

    … each input in next space in DataStored

1c(i) · 2 marks

  • 1 mark

    Storing 0 in NumberItems and then calling Initialise()

  • 1 mark

    Outputting all contents of array DataStored

1c(ii) · 2 marks

  • 1 mark

    Output showing quantity entered twice (30 and 5) with first being invalid

  • 1 mark

    Array output 3 9 4 1 2

1d(i) · 4 marks

  • 1 mark

    Procedure header (and end where appropriate) and looping through each array element

  • 1 mark

    Working inner loop …

  • 1 mark

    …comparison of elements…

  • 1 mark

    …swapping of elements

1d(ii) · 1 mark

  • 1 mark

    calling BubbleSort() and outputting array contents after

1d(iii) · 1 mark

  • 1 mark

    screenshot showing the inputs and the values in the correct order

1e(i) · 6 marks

  • 1 mark

    Function header BinarySearch taking DataToFind as a parameter

  • 1 mark

    Calculating the mid value (First + Last) \ 2 or equivalent inside loop

  • 1 mark

    Checking if the data at mid is the parameter and returning mid inside loop

  • 1 mark

    If DataToFind < mid, updating Last/Upper with mid – 1 inside loop

  • 1 mark

    If DataToFind > mid, updating First/Lower with mid + 1 inside loop

  • 1 mark

    Returning -1 when not found and a suitable loop with end criteria

1e(ii) · 3 marks

  • 1 mark

    Taking number as input

  • 1 mark

    … calling BinarySearch with input

  • 1 mark

    Outputting value returned

1e(iii) · 2 marks

  • 1 mark

    Test 1 – Accept found in index 16

  • 1 mark

    Test 2

2a(i) · 4 marks

  • 1 mark

    Class Tree declaration (and end where appropriate)

  • 1 mark

    All 5 attributes declared as private with correct identifiers and data types

  • 1 mark

    Constructor header (and end) taking 5 parameters

  • 1 mark

    Constructor assigns parameters to attributes

2a(ii) · 3 marks

  • 1 mark

    1 get method with no parameter …

  • 1 mark

    … returning correct attribute

  • 1 mark

    Remaining 4 correct

2b · 7 marks

  • 1 mark

    appropriate use of exception handling, with catch and output

  • 1 mark

    Function header (and end where appropriate) and declaration of array (of type Tree with min 9 elements)

  • 1 mark

    Opening text file Trees.txt to read and closing the file

  • 1 mark

    Reading each line of text (until EOF, or 9 times)

  • 1 mark

    Splitting each line into the 5 elements

  • 1 mark

    … casting height growth, max height and max width to integers

  • 1 mark

    … creating a new object of type Tree with the 5 values

2c · 4 marks

  • 1 mark

    Procedure heading (and end) taking one parameter (of type Tree) and using get methods to access tree name, height, width, growth

  • 1 mark

    Outputs all 4 attributes (TreeName, MaxHeight, MaxWidth, GetGrowth)

  • 1 mark

    Checks if it is evergreen…

  • 1 mark

    … correct messages are output if evergreen and otherwise

2d(i) · 2 marks

  • 1 mark

    Calling ReadData() and storing/using return value (as array of type Tree)…

  • 1 mark

    …calling PrintTrees() with first object in returned array as parameter

2d(ii) · 1 mark

  • 1 mark

    Screenshot showing output

2e(i) · 6 marks

  • 1 mark

    Procedure header (and close) taking array of Tree objects as a parameter and reading evergreen, max height and max width once as input from the user

  • 1 mark

    Looping through each array object …

  • 1 mark

    … comparing each width input >= MaxWidth, height input >= MaxHeight

  • 1 mark

    … comparing each evergreen input with Evergreen

  • 1 mark

    Calling PrintTrees() with each valid object

  • 1 mark

    Outputting suitable message if no trees appropriate

2e(ii) · 2 marks

  • 1 mark

    Taking tree name and initial height as input

  • 1 mark

    Finding the tree, calculating and outputting the number of years to get to maximum height

2e(iii) · 2 marks

  • 1 mark

    Screenshot shows the user requirements input (height 400, width 200, evergreen) and outputs the correct trees (Blue conifer and green conifer)

  • 1 mark

    Screenshot shows the tree selection input (Blue Conifer with height 100) and outputs the correct result (3 years / 3.75 / 4 years)

3a · 1 mark

  • 1 mark

    QueueData as 1D (string) array initialised to 20 null values and QueueHead initialised to -1, QueueTail initialised to -1

3b · 4 marks

  • 1 mark

    Function header (and end) taking one parameter and returns a Boolean value in all instances

  • 1 mark

    Checks if queue is full and returns FALSE

  • 1 mark

    (If not full) Inserts data item to QueueTail + 1 and increments QueueTail and returns TRUE

  • 1 mark

    Assigns QueueHead to 0 when first element is entered (this can come from incrementing)

3c · 3 marks

  • 1 mark

    Dequeue function header (and end) returning a string in all cases

  • 1 mark

    Check if queue is empty and return "false"

  • 1 mark

    (otherwise) remove value at QueueHead and increment QueueHead and return value from array

3d(i) · 6 marks

  • 1 mark

    StoreItems header (function/procedure and end where appropriate) and takes 10 inputsi

  • 1 mark

    Input is split and first 6 characters used in calculation (as integers) …

  • 1 mark

    … multiplication by 1 and 3 alternately, adding to total, dividing by 10, rounding down/cast int …

  • 1 mark

    … comparing check digit to character in position 6

  • 1 mark

    Calling Enqueue with first 6 characters when valid

  • 1 mark

    Counts and outputs number of invalid inputs

3d(ii) · 1 mark

  • 1 mark

    Calling StoreItems() and Dequeue() once and outputting a suitable message if the queue was empty and outputting the returned value if the queue was not empty

3d(iii) · 2 marks

  • 1 mark

    Data input of 10 values and output a message saying there are 4 invalid items

  • 1 mark

    999999 output

Questions

  1. 1
    Question 127 marks
    Mark scheme ›
  2. 2
    Question 231 marks
    Mark scheme ›
  3. 3
    Question 317 marks
    Mark scheme ›

More 9618 papers

Other papers from May/June 2024

Solve it on ExamPalStart