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

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 2023

Download PDF
1

A program reads data from a file and searches for specific data.

a(i)

The main program needs to read 25 integer data items from the text file Data.txt into a local 1D array, DataArray Write program code to declare the local array DataArray Save your program as Question1_J2023. Copy and paste the program code into part 1(a)(i) in the evidence document.

[1]
a(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]
b(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]
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 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]
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]
d(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]
2

A computer game is being designed that will include different vehicles. A prototype for the game is being developed using object-oriented programming. The class Vehicle stores data about the vehicles. Each vehicle has an identification name, a maximum speed, a current speed and a horizontal position. The value IncreaseAmount is added to the current speed each time the vehicle increases its speed. Vehicle ID : STRING MaxSpeed : INTEGER CurrentSpeed : INTEGER IncreaseAmount : INTEGER HorizontalPosition : INTEGER stores the identification name for the vehicle stores the maximum speed stores the current speed stores the amount CurrentSpeed increases by stores the horizontal position Constructor() GetCurrentSpeed() GetIncreaseAmount() GetHorizontalPosition() GetMaxSpeed() SetCurrentSpeed() SetHorizontalPosition() IncreaseSpeed() initialises ID, MaxSpeed and IncreaseAmount to the parameter values initialises both CurrentSpeed and HorizontalPosition to 0 returns the current speed returns the increase amount returns the horizontal position returns the maximum speed assigns the parameter to the current speed assigns the parameter to the horizontal position calculates and stores the new speed and horizontal position of the vehicle

a(i)

Write program code to declare the class Vehicle. All attributes must be private. You only need to declare the class and its constructor. Do not declare any other methods. Use your programming language’s appropriate constructor. If you are writing program code in Python, include attribute declarations using comments. Save your program as Question2_J2023. Copy and paste the program code into part 2(a)(i) in the evidence document.

[5]
a(ii)

Write program code for the get methods GetCurrentSpeed(), GetIncreaseAmount(), GetMaxSpeed() and GetHorizontalPosition() Save your program. Copy and paste the program code into part 2(a)(ii) in the evidence document.

[3]
a(iii)

Write program code for the set methods SetCurrentSpeed() and SetHorizontalPosition() Save your program. Copy and paste the program code into part 2(a)(iii) in the evidence document.

[3]
a(iv)

The method IncreaseSpeed(): • adds IncreaseAmount to the current speed • adds the updated current speed to the horizontal position. The current speed of a vehicle cannot exceed its maximum speed. Write program code for the method IncreaseSpeed() Save your program. Copy and paste the program code into part 2(a)(iv) in the evidence document.

[3]
b(i)

The child class Helicopter inherits from the parent class Vehicle. A helicopter also has a vertical position and changes the vertical position when it increases speed. Helicopter VerticalPosition : INTEGER VerticalChange : INTEGER MaxHeight : INTEGER stores the vertical position stores the amount VerticalPosition changes by stores the maximum height the helicopter can reach Constructor() GetVerticalPosition() IncreaseSpeed() takes the ID, maximum speed, increase amount, vertical change and maximum height as parameters initialises the vertical position to 0 returns the vertical position changes the current speed, horizontal and vertical position of the helicopter Write program code to declare the class Helicopter. You only need to declare the class and its constructor. You do not need to 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. Copy and paste the program code into part 2(b)(i) in the evidence document.

[5]
b(ii)

The Helicopter method IncreaseSpeed() overrides the method from the parent class and: • adds the amount of vertical change to the vertical position • adds IncreaseAmount to the current speed • adds the updated current speed to the horizontal position. The vertical position of a helicopter cannot exceed its maximum height. The current speed of a helicopter cannot exceed its maximum speed. Write program code for the method IncreaseSpeed() Save your program. Copy and paste the program code into part 2(b)(ii) in the evidence document.

[4]
c

A procedure needs to output the horizontal position and speed of a vehicle. If the vehicle is a helicopter, it also outputs the vertical position. All outputs must include appropriate messages. Write program code for this procedure. Save your program. Copy and paste the program code into part 2(c) in the evidence document.

[3]
d(i)

The main program needs to: • instantiate a car as a new vehicle with the ID "Tiger", a maximum speed of 100 and an increase amount of 20 • instantiate a new helicopter with the ID "Lion", a maximum speed of 350, an increase amount of 40, a vertical change of 3 and a maximum height of 100 • call IncreaseSpeed() twice for the car and then call the output procedure from part 2(c) for the car • call IncreaseSpeed() twice for the helicopter and then call the output procedure from part 2(c) for the helicopter. 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.

[5]
d(ii)

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

[1]
3

A program implements two stacks using 1D arrays. One stack stores the names of colours. One stack stores the names of animals.

a

The program contains the following global arrays and variables: • 1D array Animal to store the names of up to 20 animals. • 1D array Colour to store the names of up to 10 colours. • AnimalTopPointer to point to the next free space in the array Animal, initialised to 0. • ColourTopPointer to point to the next free space in the array Colour, initialised to 0. Write program code to declare the global arrays and variables. Save your program as Question3_J2023. Copy and paste the program code into part 3(a) in the evidence document.

[3]
b(i)

Study the pseudocode function PushAnimal(): FUNCTION PushAnimal(DataToPush : STRING) RETURNS BOOLEAN IF AnimalTopPointer = 20 THEN RETURN FALSE ELSE Animal[AnimalTopPointer] ← DataToPush AnimalTopPointer ← AnimalTopPointer + 1 RETURN TRUE ENDIF ENDFUNCTION Write program code for the function PushAnimal() Save your program. Copy and paste the program code into part 3(b)(i) in the evidence document.

[3]
b(ii)

Study the pseudocode function PopAnimal(): FUNCTION PopAnimal() RETURNS STRING DECLARE ReturnData : STRING IF AnimalTopPointer = 0 THEN RETURN "" ELSE ReturnData ← Animal[AnimalTopPointer - 1] AnimalTopPointer ← AnimalTopPointer - 1 RETURN ReturnData ENDIF ENDFUNCTION Write program code to declare the function PopAnimal() Save your program. Copy and paste the program code into part 3(b)(ii) in the evidence document.

[3]
b(iii)

The procedure ReadData(): • reads the animal names from the file AnimalData.txt • uses PushAnimal() to insert each name onto the stack • uses appropriate exception handling if the file does not exist. Write program code for the procedure ReadData() Save your program. Copy and paste the program code into part 3(b)(iii) in the evidence document.

[5]
b(iv)

The function PushColour() performs the same actions as PushAnimal() but inserts an item into Colour. The function PopColour() performs the same actions as PopAnimal() but removes the next item from Colour. Write program code for the functions PushColour() and PopColour() Save your program. Copy and paste the program code into part 3(b)(iv) in the evidence document.

[2]
b(v)

Amend the procedure ReadData() so that it also: • reads the colours from the text file ColourData.txt • uses PushColour() to insert each colour onto the stack • uses appropriate exception handling if the file does not exist. Save your program. Copy and paste the program code into part 3(b)(v) in the evidence document.

[2]
c

The procedure OutputItem(): • pops the next item from both Animal and Colour • outputs the colour and animal on one line, for example "black horse" If there is no data in Colour: • the animal is pushed back onto Animal • "No colour" is output. If there is no data in Animal: • the colour is pushed back onto Colour • "No animal" is output. Write program code for the procedure OutputItem() Save your program. Copy and paste the program code into part 3(c) in the evidence document.

[5]
d(i)

The main program: • calls the procedure ReadData() • calls OutputItem() four times. 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.

[1]
d(ii)

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

[1]

Mark scheme

9618/41 · May/June 2023

Download PDF

1a(i) · 1 mark

  • 1 mark

    1D array with name DataArray (with 25 elements of type Integer)

1a(ii) · 4 marks

  • 1 mark

    Opening file Data.txt to read

  • 1 mark

    Looping through all the 25/EOF …

  • 1 mark

    … reading each line and storing/appending into array

  • 1 mark

    Exception handling with appropriate output

1b(i) · 3 marks

  • 1 mark

    Procedure header (and close where appropriate) with (at least) one (integer array) parameter

  • 1 mark

    Outputting all (25) array elements …

  • 1 mark

    …on one line

1b(ii) · 1 mark

  • 1 mark

    calling PrintArray with the array as a parameter

1b(iii) · 1 mark

  • 1 mark

    screenshot

1c · 3 marks

  • 1 mark

    Function header (and close where appropriate) taking array and search value as parameters

  • 1 mark

    Looping through each array element and keeping count of the number of times the parameter appears

  • 1 mark

    Returning the calculated count value

1d(i) · 4 marks

  • 1 mark

    Prompt and reading input …

  • 1 mark

    …with validation for whole number between 0 and 100 inclusive

  • 1 mark

    Calling LinearSearch() with array and valid data input and storing/using return value

  • 1 mark

    Output of the message with return value

1d(ii) · 1 mark

  • 1 mark

    screenshot e.g.

2a(i) · 5 marks

  • 1 mark

    Class header (and close where appropriate)

  • 1 mark

    5 (private) attribute declarations including data types

  • 1 mark

    Constructor header (and close where appropriate) taking 3 parameters (min)

  • 1 mark

    Assigning ID, MaxSpeed and IncreaseAmount to parameters

  • 1 mark

    Assigning CurrentSpeed and HorizontalPosition to 0

2a(ii) · 3 marks

  • 1 mark

    1 get function header (and end where appropriate) with no parameter …

  • 1 mark

    …returning attribute (without overwriting)

  • 1 mark

    3 further correct get methods

2a(iii) · 3 marks

  • 1 mark

    1 set procedure (and end where appropriate) taking parameter …

  • 1 mark

    … assigns parameter to the attribute (without overriding)

  • 1 mark

    Second correct set method

2a(iv) · 3 marks

  • 1 mark

    Method header (and close where appropriate) with no parameter and adding IncreaseAmount to CurrentSpeed

  • 1 mark

    Checking if MaxSpeed is exceeded and limiting to max speed (remove increase or assign maximum)

  • 1 mark

    Adding updated CurrentSpeed to HorizontalPosition in all cases (whether MaxSpeed is exceeded or not)

2b(i) · 5 marks

  • 1 mark

    Class header (and end where appropriate) inheriting from Vehicle

  • 1 mark

    3 (private) attribute declarations with data types

  • 1 mark

    Constructor (and end where appropriate) with (min) 5 parameters

  • 1 mark

    Calling parent constructor with appropriate parameters

  • 1 mark

    Initialising VerticalPosition to 0 and VerticalChange and MaxHeight to attributes

2b(ii) · 4 marks

  • 1 mark

    Method header (overriding where required) with no parameter

  • 1 mark

    Adding vertical change to vertical position …

  • 1 mark

    …limiting to maximum height

  • 1 mark

    Repeating/calling/using the code from original for horizontal increase (in every case)

2c · 3 marks

  • 1 mark

    Suitable method/procedure heading (and end where appropriate) and outputting horizontal position and current speed in an appropriate message

  • 1 mark

    Checking if object is a Vehicle or Helicopter // overriding methods in each class for output // one method in each class // try except …

  • 1 mark

    …outputting vertical position only if helicopter with appropriate message

2d(i) · 5 marks

  • 1 mark

    Instantiating an object of type Vehicle with correct parameters ("Tiger", 100, 20)

  • 1 mark

    Instantiating an object of type Helicopter with correct parameters ("Lion", 350, 40, 3, 100)

  • 1 mark

    Calling IncreaseSpeed() twice for the car

  • 1 mark

    Calling IncreaseSpeed() twice for the helicopter

  • 1 mark

    Calling the output for both objects

2d(ii) · 1 mark

  • 1 mark

    Screenshot of results e.g.

3a · 3 marks

  • 1 mark

    (Global) Animal array (with 20 string elements)

  • 1 mark

    (Global) Colour array (with 10 string elements)

  • 1 mark

    (Global) AnimalTopPointer and ColourTopPointer initialised to 0

3b(i) · 3 marks

  • 1 mark

    Function header (and close where appropriate) with parameter, checking if full (AnimalTopPointer = 20) and returning false

  • 1 mark

    If not full, inserting parameter value into AnimalTopPointer

  • 1 mark

    …incrementing pointer and returning true

3b(ii) · 3 marks

  • 1 mark

    Procedure header (and end where appropriate) with no parameter, checking if empty (AnimalTopPointer = 0) and returning empty string

  • 1 mark

    If not empty returning the top data item (AnimalTopPointer-1)

  • 1 mark

    … and decrementing AnimalTopPointer

3b(iii) · 5 marks

  • 1 mark

    Procedure header (and close where appropriate) and opening correct file for read

  • 1 mark

    Looping until end of file // looping until all animal names read in // looping 8 times

  • 1 mark

    Calling PushAnimal() with each line read from file (for all lines)

  • 1 mark

    Closing the file

  • 1 mark

    Exception handling with appropriate error message

3b(iv) · 2 marks

  • 1 mark

    PushColour function

  • 1 mark

    PopColour function

3b(v) · 2 marks

  • 1 mark

    Opening ColourData.txt to read, reading until EOF, closing file and exception handling

  • 1 mark

    Using PushColour() to store each item read from the file for all lines

3c · 5 marks

  • 1 mark

    Procedure heading (and close where appropriate) and outputting the colour and animal using PopColour() and PopAnimal() (only if both are successfully popped)

  • 1 mark

    Checking if no colour and outputting "No colour" …

  • 1 mark

    ….pushing the removed animal back onto the stack

  • 1 mark

    Checking if no animal and outputting "No animal" …

  • 1 mark

    …pushing the removed colour back onto the stack

3d(i) · 1 mark

  • 1 mark

    Calling ReadData() and calling OutputItem() 4 times

3d(ii) · 1 mark

  • 1 mark

    output

Questions

  1. 1
    Question 118 marks
    Mark scheme ›
  2. 2
    Question 232 marks
    Mark scheme ›
  3. 3
    Question 325 marks
    Mark scheme ›

More 9618 papers

Other papers from May/June 2023

Solve it on ExamPalStart