A Level Computer Science 9618 Paper 41, Oct/Nov 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 · Oct/Nov 2024

Download PDF
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(i)

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(). Save your program. Copy and paste the program code into part 1(b)(i) in the evidence document.

[2]
b(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]
b(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(i)

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(). Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document.

[3]
d(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]
d(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

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 Constructor() — initialises Name, MaxFenceHeight and 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

a(i)

Write program code to declare the class Horse and its constructor. 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]
a(ii)

The get methods GetName() and GetMaxFenceHeight() 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(i)

The array Horses stores objects of type Horse. The program has two horses: • The horse named ‘Beauty’ can jump a maximum height of 150cm and has a success percentage rate of 72%. • The horse named ‘Jet’ can jump a maximum height of 160cm 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]
b(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(i)

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 Constructor() — initialises Height and Risk to its parameter values 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. 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]
c(ii)

The array Course stores four Fence objects. The user inputs the height and risk for 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 maximum height a horse can jump, the success percentage is 20% of the horse’s PercentageSuccess. The risk does not affect this value. If the height of the fence is less than or equal to the maximum height a horse can jump, the risk gives a modifier value to multiply with the horse’s PercentageSuccess. The risk values and their modifiers are given in this table: Risk | Modifier 5 | 0.6 4 | 0.7 3 | 0.8 2 | 0.9 1 | 1.0 For example: • The horse Jet has PercentageSuccess of 65 and MaxFenceHeight of 160. • A fence has a height of 140 and a risk of 3. • The height of the fence is less than the horse’s MaxFenceHeight, therefore the risk is used. • The risk of 3 gives the modifier 0.8. • The modifier 0.8 is multiplied by the horse’s PercentageSuccess of 65, which gives 52. • The chance of the horse successfully jumping this fence is 52%. The method Success() in the Horse class: • takes the height and risk of a fence as parameters • calculates the percentage chance of success for that horse jumping the fence without knocking it down • returns the calculated percentage chance of success as a real number. Write program code for Success(). Save your program. Copy and paste the program code into part 2(d) in the evidence document.

[5]
e(i)

Write program code to amend the main program to: • calculate and output the chance of the first horse jumping each of the four fences without knocking each fence down • calculate and output the chance of the second horse jumping each of the four fences without knocking each fence down. All outputs must have appropriate messages including the name of the horse and the fence number. An example output for one horse jumping two fences is: "The horse Fox at fence 1 has a 68% chance of success The horse Fox at fence 2 has a 72% chance of success" Save your program. Copy and paste the program code into part 2(e)(i) in the evidence document.

[3]
e(ii)

Write program code to amend the main program to: • calculate and output the average chance of success for each horse jumping over all four fences without knocking each fence down (the average is the total of values divided by the quantity of values). An example output for one horse jumping all of the fences is: "The horse Fox has an average 70% chance of jumping over all four fences" • output the name of the horse that has the highest average chance of success. You can assume that each average will be different. All outputs must have appropriate messages. Save your program. Copy and paste the program code into part 2(e)(ii) in the evidence document.

[2]
e(iii)

Test your program with the following input data for four fences: Height | Risk 152 | 5 121 | 1 130 | 3 145 | 4 Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 2(e)(iii) in the evidence document.

[2]
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 not full | insert the data in the index pointed to by FirstEmpty change the pointer to the index pointed to by FirstNode 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(i)

The procedure OutputLinkedList() outputs the data in the linked list in order by following the pointers from FirstNode. Write program code for OutputLinkedList(). Save your program. Copy and paste the program code into part 3(c)(i) in the evidence document.

[2]
c(ii)

Amend the main program to call InsertData() and then OutputLinkedList(). Save your program. Copy and paste the program code into part 3(c)(ii) in the evidence document.

[1]
c(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(i)

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(). Save your program. Copy and paste the program code into part 3(d)(i) in the evidence document.

[5]
d(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]
d(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]

Mark scheme

9618/41 · Oct/Nov 2024

Download PDF

1a · 6 marks

  • 1 mark

    Function declaration (and close where appropriate)

  • 1 mark

    Declaration/use of an array (with space/initialised with 45 spaces/strings)

  • 1 mark

    Opening the file Data.txt for read and closing in an appropriate place

  • 1 mark

    Looping through all file contents/Looping 45 times and reading each line …

  • 1 mark

    … storing all items from file into array

  • 1 mark

    Returning the populated array

1b(i) · 2 marks

  • 1 mark

    Function header (and end where appropriate) taking (min) one parameter

  • 1 mark

    Looping through each parameter array element, concatenating with space and returning

1b(ii) · 3 marks

  • 1 mark

    Calling ReadData() and storing returned array …

  • 1 mark

    … calling FormatArray() with returned array

  • 1 mark

    Outputting return value from FormatArray()

1b(iii) · 1 mark

  • 1 mark

    1 mark for output showing all colours in one string

1c · 4 marks

  • 1 mark

    Function header (and end where appropriate) taking (min) two parameters and returns a value in all cases

  • 1 mark

    Looping through each character in each string parameter …

  • 1 mark

    … return 1 when first parameter < second

  • 1 mark

    … return 2 when first parameter > second

1d(i) · 3 marks

  • 1 mark

    Bubble sort function header taking array parameter and returns sorted array in all cases

  • 1 mark

    Comparing strings using CompareStrings() and correctly swapping values when needed

  • 1 mark

    Correct bubble sort that sorts the data correctly

1d(ii) · 2 marks

  • 1 mark

    Calling Bubble() with array as parameter and using/storing return value

  • 1 mark

    Calling FormatArray() with return value from Bubble() and outputting return value

1d(iii) · 1 mark

  • 1 mark

    1 mark for sorted data

2a(i) · 4 marks

  • 1 mark

    Class Horse declaration (and end where appropriate)

  • 1 mark

    All 3 attributes declared as private with appropriate data types (declaration or comment)

  • 1 mark

    Constructor header (and end) taking 3 parameters (constructor must be within class) …

  • 1 mark

    … constructor assigns parameters to attributes

2a(ii) · 3 marks

  • 1 mark

    1 get method header with no parameter …

  • 1 mark

    … returning correct attribute (without change)

  • 1 mark

    2nd get method correct

2b(i) · 5 marks

  • 1 mark

    Instantiating one object of type Horse with correct data …

  • 1 mark

    … and storing in first element of a 1D array Horses

  • 1 mark

    Instantiating second object of type Horse with correct data and storing in second index of the array

  • 1 mark

    Outputting name of both horse objects from array …

  • 1 mark

    … using GetName()

2b(ii) · 1 mark

  • 1 mark

    1 mark for both names output: Beauty Jet

2c(i) · 4 marks

  • 1 mark

    Class Fence header (and end where appropriate) with no inheritance

  • 1 mark

    Height and Risk private with integer data type

  • 1 mark

    Constructor taking 2 parameters and storing in attributes (constructor must be within class)

  • 1 mark

    2 get methods (no parameter) returning correct attributes (within class)

2c(ii) · 5 marks

  • 1 mark

    Declaration/use of array Course of type Fence (with at least 4 elements)

  • 1 mark

    Taking Height and Risk as input four times and store/use

  • 1 mark

    Instantiating a Fence object for each set of valid input values and storing in array

  • 1 mark

    Taking each height as input until it is between 70 and 180 (inclusive)

  • 1 mark

    Taking each risk as input until it is between 1 and 5 (inclusive)

2d · 5 marks

  • 1 mark

    Method header taking 2 parameters (and end where appropriate, returning real)

  • 1 mark

    Checking if fence height parameter is more than max attribute for that horse, if true multiplying percentage success by 0.2

  • 1 mark

    (Otherwise) selection checking risk value parameter between 1 and 5, multiplying modifier by percentage success

  • 1 mark

    Returning correct value as a real number in all instances

  • 1 mark

    Correct use of attributes and parameters throughout

2e(i) · 3 marks

  • 1 mark

    Calling Success() for each horse with the height and risk of all 4 fences …

  • 1 mark

    … using get methods for height and risk of each fence

  • 1 mark

    … outputting the horse name, fence number and calculated success at fence in appropriate message

2e(ii) · 2 marks

  • 1 mark

    Calculating average of all 4 fences for each horse and outputting in suitable message

  • 1 mark

    Identifying the highest percentage of success and outputting the horse's name in an appropriate message

2e(iii) · 2 marks

  • 1 mark

    Outputting showing correct input values for all fences, and correct chance for each horse on each jump

  • 1 mark

    Outputs of average chance of each horse and horse name with highest average

3a · 2 marks

  • 1 mark

    LinkedList declared as 2D array with (min) 20 × 2 elements (Integer) with all data initialised to -1, all nodes linked correctly

  • 1 mark

    (Global) FirstNode (Int) initialised as -1 and (global) FirstEmpty (Int) initialised as 0

3b · 6 marks

  • 1 mark

    Procedure header (and end) taking (min) 5 data items as input from the user

  • 1 mark

    Checking if linked list is full (FirstEmpty = -1) …

  • 1 mark

    …ending procedure/loop/not doing anything further

  • 1 mark

    (otherwise) LinkedList[FirstEmpty, 0] = data input

  • 1 mark

    LinkedList[FirstEmpty, 1] = FirstNode

  • 1 mark

    FirstNode = FirstEmpty

3c(i) · 2 marks

  • 1 mark

    Procedure header (and end) starting with node at index FirstNode and outputting data LinkedList[FirstNode, 0]

  • 1 mark

    Following pointers until end reached and outputting data for each node

3c(ii) · 1 mark

  • 1 mark

    1 mark for calling InsertData() then OutputLinkedList()

3c(iii) · 1 mark

  • 1 mark

    1 mark for inputs of 5 1 2 3 8 and output of 8 3 2 1 5

3d(i) · 5 marks

  • 1 mark

    Procedure header (and end) with parameter

  • 1 mark

    Checking data in FirstNode against parameter …

  • 1 mark

    … (if found) updating FirstNode to LinkedList[FirstNode, 1]

  • 1 mark

    (Otherwise) following pointers in loop/recursive call …

  • 1 mark

    …comparing to data to remove each time

3d(ii) · 1 mark

  • 1 mark

    1 mark for calling RemoveData(5), outputting "After", calling OutputLinkedList()

3d(iii) · 1 mark

  • 1 mark

    1 mark for input and output. Test data 1: Input 5 6 8 9 5 ‘After’ Output: 9 8 6 5 Test data 2: Input 10 7 8 5 6 “After” Output: 6 8 7 10

Questions

  1. 1
    Question 122 marks
    Mark scheme ›
  2. 2
    Question 234 marks
    Mark scheme ›
  3. 3
    Question 319 marks
    Mark scheme ›

More 9618 papers

Other papers from Oct/Nov 2024

Solve it on ExamPalStart