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

Download PDF
1

A program stores lower-case letters in two stacks. One stack stores vowels (a, e, i, o, u) and one stack stores consonants (letters that are not vowels). Each stack is implemented as a 1D array.

a(i)

Write program code to declare two 1D global arrays: StackVowel and StackConsonant. Each array needs to store up to 100 letters. The index of the first element in each array is 0. If you are writing in Python, include declarations using comments. Save your program as Question1_N23. Copy and paste the program code into part 1(a)(i) in the evidence document.

[2]
a(ii)

The global variable VowelTop is a pointer that stores the index of the next free space in StackVowel. The global variable ConsonantTop is a pointer that stores the index of the next free space in StackConsonant. VowelTop and ConsonantTop are both initialised to 0. Write program code to declare and initialise the two variables. If you are writing in Python, include declarations using comments. Save your program. Copy and paste the program code into part 1(a)(ii) in the evidence document.

[1]
b(i)

The procedure PushData() takes one letter as a parameter. If the parameter is a vowel, it is pushed onto StackVowel and the relevant pointer updated. If the stack is full, a suitable message is output. If the parameter is a consonant, it is pushed onto StackConsonant and the relevant pointer updated. If the stack is full, a suitable message is output. You do not need to validate that the parameter is a letter. Write program code for PushData(). Save your program. Copy and paste the program code into part 1(b)(i) in the evidence document.

[6]
b(ii)

The file StackData.txt stores 100 lower-case letters. The procedure ReadData() reads each letter from the file and uses PushData() to push each letter onto its appropriate stack. Use appropriate exception handling if the file does not exist. Write program code for ReadData(). Save your program. Copy and paste the program code into part 1(b)(ii) in the evidence document.

[6]
c

The function PopVowel() removes and returns the data at the top of StackVowel and updates the relevant pointer(s). The function PopConsonant() removes and returns the data from the top of StackConsonant and updates the relevant pointer(s). If either stack is empty, the string "No data" must be returned. Write program code to declare PopVowel() and PopConsonant(). Save your program. Copy and paste the program code into part 1(c) in the evidence document.

[5]
d(i)

The program first needs to call ReadData() and then: 1. prompt the user to input their choice of vowel or consonant 2. take, as input, the user’s choice 3. depending on the user’s choice, call PopVowel() or PopConsonant() and store the return value. The three steps are repeated until 5 letters have been successfully returned and stored. If either stack is empty at any stage, an appropriate message must be output. Once 5 letters have been successfully returned and stored, they are output on one line, for example: abyti Write program code for the main program. Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document.

[6]
d(ii)

Test your program with the following inputs: vowel consonant consonant vowel vowel 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

An integer is said to be divisible by another integer if the result of the division is also an integer. For example: 10 is divisible by 1, 2, 5 and 10: • 10 ÷ 1 = 10 • 10 ÷ 2 = 5 • 10 ÷ 5 = 2 • 10 ÷ 10 = 1 10 is not divisible by 4: • 10 ÷ 4 = 2.5 1, 2, 5 and 10 are said to be the divisors of 10. The iterative function IterativeCalculate() totals all the divisors of its integer parameter and returns this total. Example 1: if the parameter is 10, the total will be 18 (1 + 2 + 5 + 10) . Example 2: if the parameter is 4, the total will be 7 (1 + 2 + 4) . A pseudocode algorithm for IterativeCalculate() is shown. FUNCTION IterativeCalculate(Number : INTEGER) RETURNS INTEGER DECLARE Total : Integer DECLARE ToFind : Integer ToFind ← Number Total ← 0 WHILE Number <> 0 IF ToFind MODULUS Number = 0 THEN Total ← Total + Number ENDIF Number ← Number - 1 ENDWHILE RETURN Total ENDFUNCTION The operator MODULUS calculates the remainder when one number is divided by another.

a(i)

Write program code for IterativeCalculate(). Save your program as Question2_N23. Copy and paste the program code into part 2(a)(i) in the evidence document.

[5]
a(ii)

Write program code to call IterativeCalculate() with 10 as the parameter and output the return value. Save your program. Copy and paste the program code into part 2(a)(ii) in the evidence document.

[2]
a(iii)

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

[1]
b(i)

IterativeCalculate() has been rewritten as the recursive function RecursiveValue(). A pseudocode algorithm for RecursiveValue() is given. The function is incomplete. FUNCTION RecursiveValue(Number : INTEGER, ToFind : INTEGER) RETURNS INTEGER IF Number = .............. THEN RETURN 0 ELSE IF ToFind .............. Number = 0 THEN RETURN .............. + RecursiveValue(Number - 1, ToFind) ELSE .............. RecursiveValue(Number - 1, ..............) ENDIF ENDIF ENDFUNCTION Write program code for RecursiveValue(). Save your program. Copy and paste the program code into part 2(b)(i) in the evidence document.

[7]
b(ii)

Write program code to call RecursiveValue() with 50 as the first parameter and 50 as the second parameter and output the return value. Save your program. Copy and paste the program code into part 2(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 2(b)(iii) in the evidence document.

[1]
3

A computer game is written using object-oriented programming. The game has multiple characters. The class Character stores data about the game characters. Each character has a name, date of birth, intelligence value and speed value. Character CharacterName : STRING | stores the name of the character DateOfBirth : DATE | stores the date of birth of the character Intelligence : REAL | stores the intelligence value of the character Speed : INTEGER | stores the speed value of the character Constructor() | initialises CharacterName, DateOfBirth, Intelligence and Speed to the parameter values SetIntelligence() | assigns the value of the parameter to Intelligence GetIntelligence() | returns the value of Intelligence GetName() | returns the name of the character ReturnAge() | calculates and returns the age of the character as an integer Learn() | increases the value of Intelligence by 10%

a(i)

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

[5]
a(ii)

The get methods GetIntelligence() and GetName() return the attribute values. Write program code for the methods GetIntelligence() and GetName(). Save your program. Copy and paste the program code into part 3(a)(ii) in the evidence document.

[3]
a(iii)

The method SetIntelligence() assigns the value of its parameter to the attribute. Write program code for SetIntelligence(). Save your program. Copy and paste the program code into part 3(a)(iii) in the evidence document.

[2]
a(iv)

The method Learn() increases the current value of Intelligence by 10%. Write program code for Learn(). Save your program. Copy and paste the program code into part 3(a)(iv) in the evidence document.

[1]
a(v)

The method ReturnAge() calculates and returns the age of the character in years as an integer. Assume that the current year is 2023 and only use the year from the date of birth for the calculation. For example, the method returns 18 if the character was born on any date in 2005. Write program code for the method ReturnAge(). Save your program. Copy and paste the program code into part 3(a)(v) in the evidence document.

[2]
b(i)

Write program code to create a new instance of Character with the identifier FirstCharacter. The name of the character is Royal, date of birth is 1 January 2019, intelligence is 70 and speed is 30. Save your program. Copy and paste the program code into part 3(b)(i) in the evidence document.

[2]
b(ii)

Write program code to call the method Learn() for the character created in part 3(b)(i). Output the name, age and intelligence of the character in an appropriate message. Save your program. Copy and paste the program code into part 3(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 3(b)(iii) in the evidence document.

[1]
c(i)

The class MagicCharacter inherits from the class Character. A magic character has an element, for example, water. This element changes how they learn. The magic character’s element is stored in the additional attribute Element. MagicCharacter Element : STRING | stores the element for the character Constructor() | takes Element, CharacterName, DateOfBirth, Intelligence and Speed as parameters calls its parent class constructor with the appropriate values initialises Element to its parameter value Learn() | alters the intelligence of the character depending on the character’s element Write program code to declare the class MagicCharacter and its constructor. Do not declare the other method. Use your programming language’s 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.

[5]
c(ii)

The method Learn() overrides the parent class method and increases the intelligence depending on the character’s element. • If the element is fire or water, intelligence increases by 20%. • If the element is earth, intelligence increases by 30%. • If the element is not fire, water or earth the intelligence increases by 10%. Write program code for Learn(). Save your program. Copy and paste the program code into part 3(c)(ii) in the evidence document.

[3]
d(i)

Write program code to create a new instance of MagicCharacter with the identifier FirstMagic. The name of the character is Light, date of birth is 3 March 2018, intelligence is 75, speed is 22 and element is fire. Save your program. Copy and paste the program code into part 3(d)(i) in the evidence document.

[2]
d(ii)

Write program code to call the method Learn() for the character created in part 3(d)(i). Output the name, age and intelligence of the character in an appropriate message. Save your program. Copy and paste the program code into part 3(d)(ii) in the evidence document.

[1]
d(iii)

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

[1]

Mark scheme

9618/42 · Oct/Nov 2023

Download PDF

1a(i) · 2 marks

  • 1 mark

    Two arrays with correct identifiers of type string/character

  • 1 mark

    Each has 100 elements

1a(ii) · 1 mark

  • 1 mark

    Declaring both variables as type integer global and initialised to 0

1b(i) · 6 marks

  • 1 mark

    Procedure PushData() heading (and end where appropriate) taking one parameter

  • 1 mark

    Checking if parameter is a (lowercase) vowel …

  • 1 mark

    … checking if StackVowel is full and outputting suitable message

  • 1 mark

    … otherwise inserting parameter in next position

  • 1 mark

    … incrementing VowelTop

  • 1 mark

    Repeated for Consonant

1b(ii) · 6 marks

  • 1 mark

    Procedure header ReadData() with no parameter

  • 1 mark

    Opening StackData.txt to read and closing file

  • 1 mark

    Looping until EOF // Looping 100 times

  • 1 mark

    Read each item from the file

  • 1 mark

    Calling PushData() with each value as parameter

  • 1 mark

    Appropriate exception handling with suitable output

1c · 5 marks

  • 1 mark

    One function header with no parameter

  • 1 mark

    Checking if stack is empty and returning "No data"

  • 1 mark

    …otherwise, decrementing correct pointer

  • 1 mark

    Returning value at top of stack

  • 1 mark

    2nd function fully correct

1d(i) · 6 marks

  • 1 mark

    Calling ReadData()

  • 1 mark

    Looping until 5 letters successfully accessed

  • 1 mark

    Prompt and read in input of choice …

  • 1 mark

    … if vowel is input calling PopVowel() and if consonant calling PopConsonant() …

  • 1 mark

    … storing return values

  • 1 mark

    Outputting appropriate message if no vowels and if no consonants (stacks full) within loop

1d(ii) · 1 mark

  • 1 mark

    showing input in order vowel, cons, cons, vowel, vowel. Output is then utxoe

2a(i) · 5 marks

  • 1 mark

    Function header with parameter

  • 1 mark

    Correct loop

  • 1 mark

    Modulus calculation

  • 1 mark

    Return of correct value at correct place

  • 1 mark

    Remainder of function correct

2a(ii) · 2 marks

  • 1 mark

    Calling IterativeCalculate(10)

  • 1 mark

    Outputting return value

2a(iii) · 1 mark

  • 1 mark

    screenshot showing 18

2b(i) · 7 marks

  • 1 mark

    gap (1)

  • 1 mark

    gap (2)

  • 1 mark

    gap (3)

  • 1 mark

    gap (4)

  • 1 mark

    gap (5)

  • 1 mark

    recursive calls both accurate and in correct places

  • 1 mark

    remainder of function with nothing superfluous

2b(ii) · 1 mark

  • 1 mark

    calling RecursiveValue(50,50)and outputting return value

2b(iii) · 1 mark

  • 1 mark

    screenshot showing 93

3a(i) · 5 marks

  • 1 mark

    Class declaration

  • 1 mark

    Four attributes with correct data types

  • 1 mark

    Constructor header

  • 1 mark

    … taking 4 parameters

  • 1 mark

    Setting attributes to parameter values

3a(ii) · 3 marks

  • 1 mark

    1 get header with no parameter …

  • 1 mark

    … returning attribute

  • 1 mark

    Second correct get method

3a(iii) · 2 marks

  • 1 mark

    Set header with 1 parameter …

  • 1 mark

    … assigns parameter to attribute

3a(iv) · 1 mark

  • 1 mark

    method multiplying attribute intelligence by 1.1 (or equivalent) and storing in attribute.

3a(v) · 2 marks

  • 1 mark

    Method (function) header (and end where appropriate) no parameter, returning a calculated age

  • 1 mark

    Extracting attribute year of birth from date and subtracting from 2023

3b(i) · 2 marks

  • 1 mark

    Creating new instance of Character with identifier FirstCharacter …

  • 1 mark

    … sending correct values as parameters

3b(ii) · 3 marks

  • 1 mark

    Calling Learn() for FirstCharacter

  • 1 mark

    Calling ReturnAge() and outputting return value

  • 1 mark

    Outputting name and intelligence using gets with suitable message

3b(iii) · 1 mark

  • 1 mark

    screenshot with Royal, 4 years, 77 intelligence e.g.

3c(i) · 5 marks

  • 1 mark

    Class header inheriting from Character

  • 1 mark

    Declaring Element as string

  • 1 mark

    Constructor header taking 5 parameters …

  • 1 mark

    … calling parent constructor with the 4 parameters

  • 1 mark

    … assigning parameter to Element

3c(ii) · 3 marks

  • 1 mark

    Method header overriding parent method but no parameters

  • 1 mark

    Checking element value …

  • 1 mark

    … correct calculations with attribute intelligence and storing

3d(i) · 2 marks

  • 1 mark

    Declaring MagicCharacter with identifier FirstMagic …

  • 1 mark

    … with correct parameters

3d(ii) · 1 mark

  • 1 mark

    calling Learn() for FirstMagic and outputting all required data in appropriate message using gets.

3d(iii) · 1 mark

  • 1 mark

    screenshot e.g.

Questions

  1. 1
    Question 127 marks
    Mark scheme ›
  2. 2
    Question 217 marks
    Mark scheme ›
  3. 3
    Question 331 marks
    Mark scheme ›

More 9618 papers

Other papers from Oct/Nov 2023

Solve it on ExamPalStart