9618/42 · October/November 2023 · Worked solutions

Step-by-step solutions based on the mark scheme (not a mark-scheme dump).

Question 1

Paper page 2 for Q1
Original paper page 2

Part 1(a)(i) — solution

  1. Two arrays with correct identifiers of type string/character
  2. Each has 100 elements

Visual Basic (VB.NET)

Dim StackVowel(0 To 99) As Char
               Dim StackConsonant(0 To 99) As Char

Python

StackVowel = [] #string 100
               StackConsonant = [] #string 100

 2023                                                          Page 4 of 34

9618/42                                         Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Two arrays with correct identifiers of type string/character
  • Each has 100 elements

Part 1(a)(ii) — solution

  1. Declaring both variables as type integer global and initialised to 0

Visual Basic (VB.NET)

Dim VowelTop As Integer = 0
               Dim ConsonantTop As Integer = 0

Python

global VowelTop #integer
               global ConsonantTop #integer
               #main
               VowelTop = 0
               ConsonantTop = 0

 2023                                                           Page 5 of 34

9618/42                                       Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Declaring both variables as type integer global and initialised to 0

Part 1(b)(i) — solution

  1. Procedure PushData() heading (and end where appropriate) taking one parameter
  2. Checking if parameter is a (lowercase) vowel …
  3. … checking if StackVowel is full and outputting suitable message
  4. … otherwise inserting parameter in next position
  5. … incrementing VowelTop
  6. Repeated for Consonant

Mark points

  • Procedure PushData() heading (and end where appropriate) taking one parameter
  • Checking if parameter is a (lowercase) vowel …
  • … checking if StackVowel is full and outputting suitable message
  • … otherwise inserting parameter in next position
  • … incrementing VowelTop
  • Repeated for Consonant

Part 1(b)(i) — solution

  1. If Letter = "a" Or Letter = "e" Or Letter = "i" Or Letter = "o" Or Letter = "u" Then
  2. If VowelTop = 100 Then
  3. StackVowel(VowelTop) = Letter
  4. VowelTop += 1
  5. If ConsonantTop = 100 Then
  6. StackConsonant(ConsonantTop) = Letter
  7. ConsonantTop += 1
  8. if Letter == "a" or Letter == "e" or Letter == "i" or Letter == "o" or Letter == "u":
  9. if VowelTop == 100:
  10. VowelTop = VowelTop + 1
  11. if ConsonantTop == 100:
  12. ConsonantTop = ConsonantTop + 1

Visual Basic (VB.NET)

Sub PushData(Letter As Char)
                  If Letter = "a" Or Letter = "e" Or Letter = "i" Or Letter = "o" Or Letter = "u" Then
                     If VowelTop = 100 Then
                         Console.WriteLine("Vowel stack full")
                     Else
                         StackVowel(VowelTop) = Letter
                         VowelTop += 1
                     End If
                  Else
                     If ConsonantTop = 100 Then
                         Console.WriteLine("Consonant stack full")
                     Else
                         StackConsonant(ConsonantTop) = Letter
                         ConsonantTop += 1
                     End If
                  End If
               End Sub

Python

def PushData(Letter):
                  global VowelTop
                  global ConsonantTop
                  if Letter == "a" or Letter == "e" or Letter == "i" or Letter == "o" or Letter == "u":
                     if VowelTop == 100:
                        print("Vowel stack full")
                     else:
                        StackVowel.append(Letter)
                        VowelTop = VowelTop + 1
                  else:
                     if ConsonantTop == 100:
                        print("Consonant stack full")
                     else:
                        StackConsonant.append(Letter)
                        ConsonantTop = ConsonantTop + 1

 2023                                               Page 7 of 34

9618/42                                        Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • If Letter = "a" Or Letter = "e" Or Letter = "i" Or Letter = "o" Or Letter = "u" Then
  • If VowelTop = 100 Then
  • StackVowel(VowelTop) = Letter
  • VowelTop += 1
  • If ConsonantTop = 100 Then
  • StackConsonant(ConsonantTop) = Letter
  • ConsonantTop += 1
  • if Letter == "a" or Letter == "e" or Letter == "i" or Letter == "o" or Letter == "u":
  • if VowelTop == 100:
  • VowelTop = VowelTop + 1
  • if ConsonantTop == 100:
  • ConsonantTop = ConsonantTop + 1

Part 1(b)(ii) — solution

  1. Procedure header ReadData() with no parameter
  2. Opening StackData.txt to read and closing file
  3. Looping until EOF // Looping 100 times
  4. Read each item from the file
  5. Calling PushData() with each value as parameter
  6. Appropriate exception handling with suitable output

Visual Basic (VB.NET)

Sub ReadData()
                      Try
                          Dim DataReader As New System.IO.StreamReader("StackData.txt")

                           Do Until DataReader.EndOfStream
                              PushData(DataReader.ReadLine())
                           Loop
                           DataReader.Close()
 2023                                                             Page 8 of 34

9618/42                                  Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Procedure header ReadData() with no parameter
  • Opening StackData.txt to read and closing file
  • Looping until EOF // Looping 100 times
  • Read each item from the file
  • Calling PushData() with each value as parameter
  • Appropriate exception handling with suitable output

Part 1(b)(ii) — solution

  1. DataFile = open("StackData.txt")

Python

def ReadData():
                  try:
                     DataFile = open("StackData.txt")
                     for Line in DataFile:
                         PushData(Line.strip())
                     DataFile.close()
                  except:
                     print("File not found")

 2023                                                 Page 9 of 34

9618/42                                         Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • DataFile = open("StackData.txt")

Part 1(c) — solution

  1. One function header with no parameter
  2. Checking if stack is empty and returning "No data"
  3. …otherwise, decrementing correct pointer
  4. Returning value at top of stack
  5. 2nd function fully correct

Mark points

  • One function header with no parameter
  • Checking if stack is empty and returning "No data"
  • …otherwise, decrementing correct pointer
  • Returning value at top of stack
  • 2nd function fully correct

Part 1(c) — solution

  1. If VowelTop - 1 >= 0 Then
  2. VowelTop -= 1
  3. Dim DataToReturn As Char = StackVowel(VowelTop)
  4. If ConsonantTop - 1 >= 0 Then
  5. ConsonantTop -= 1
  6. Dim DataToReturn As Char = StackConsonant(ConsonantTop)
  7. if VowelTop - 1 >= 0:
  8. VowelTop = VowelTop - 1
  9. DataToReturn = StackVowel[VowelTop]

Visual Basic (VB.NET)

Function PopVowel()
                     If VowelTop - 1 >= 0 Then
                        VowelTop -= 1
                        Dim DataToReturn As Char = StackVowel(VowelTop)
                        Return DataToReturn
                     Else
                        Return "No data"
                     End If
                  End Function

                  Function PopConsonant()
                     If ConsonantTop - 1 >= 0 Then
                        ConsonantTop -= 1
                        Dim DataToReturn As Char = StackConsonant(ConsonantTop)
                        Return DataToReturn
                     Else
                        Return "No data"
                     End If
                  End Function

Python

def PopVowel():
                  global VowelTop
                  global ConsonantTop
                  if VowelTop - 1 >= 0:
                     VowelTop = VowelTop - 1
                     DataToReturn = StackVowel[VowelTop]
                     del StackVowel[-1]
                     return DataToReturn
                  else:
                     return "No data"

 2023                                               Page 11 of 34

9618/42                                Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • If VowelTop - 1 >= 0 Then
  • VowelTop -= 1
  • Dim DataToReturn As Char = StackVowel(VowelTop)
  • If ConsonantTop - 1 >= 0 Then
  • ConsonantTop -= 1
  • Dim DataToReturn As Char = StackConsonant(ConsonantTop)
  • if VowelTop - 1 >= 0:
  • VowelTop = VowelTop - 1
  • DataToReturn = StackVowel[VowelTop]

Part 1(c) — solution

  1. if ConsonantTop - 1 >= 0:
  2. ConsonantTop = ConsonantTop - 1
  3. DataToReturn = StackConsonant[ConsonantTop]

Mark points

  • if ConsonantTop - 1 >= 0:
  • ConsonantTop = ConsonantTop - 1
  • DataToReturn = StackConsonant[ConsonantTop]

Part 1(d)(i) — solution

  1. Calling ReadData()
  2. Looping until 5 letters successfully accessed
  3. Prompt and read in input of choice …
  4. … if vowel is input calling PopVowel() and if consonant calling PopConsonant() …
  5. … storing return values
  6. Outputting appropriate message if no vowels and if no consonants (stacks full) within loop
  7. Outputting the five returned letters on one line

Mark points

  • Calling ReadData()
  • Looping until 5 letters successfully accessed
  • Prompt and read in input of choice …
  • … if vowel is input calling PopVowel() and if consonant calling PopConsonant() …
  • … storing return values
  • Outputting appropriate message if no vowels and if no consonants (stacks full) within loop
  • Outputting the five returned letters on one line

Part 1(d)(i) — solution

  1. DataAccessed = PopConsonant();
  2. if(DataAccessed.equals("No data") == false){
  3. Letters = Letters + DataAccessed;
  4. Flag = true;
  5. VowelTop = 0
  6. ConsonantTop = 0
  7. Dim Letters As String = ""
  8. Dim Flag As Boolean = False
  9. For x = 0 To 4
  10. Flag = False
  11. While Flag = False
  12. Choice = Console.ReadLine().ToLower()
  13. If Choice = "vowel" Then
  14. DataAccessed = PopVowel()
  15. Letters = Letters & DataAccessed
  16. Flag = True

Visual Basic (VB.NET)

Sub Main(args As String())
                  VowelTop = 0
                  ConsonantTop = 0
                  ReadData()
                  Dim Letters As String = ""
                  Dim Flag As Boolean = False
                  Dim Choice As String
                  Dim DataAccessed As String
                  For x = 0 To 4
                     Flag = False
                     While Flag = False
                         Console.WriteLine("Vowel or Consonant?")
                         Choice = Console.ReadLine().ToLower()
                         If Choice = "vowel" Then
                            DataAccessed = PopVowel()
                            If DataAccessed <> "No data" Then
                               Letters = Letters & DataAccessed
                               Flag = True
                            Else
                               Console.WriteLine("No vowels left")

 2023                                                 Page 14 of 34

9618/42                                Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • DataAccessed = PopConsonant();
  • if(DataAccessed.equals("No data") == false){
  • Letters = Letters + DataAccessed;
  • Flag = true;
  • VowelTop = 0
  • ConsonantTop = 0
  • Dim Letters As String = ""
  • Dim Flag As Boolean = False
  • For x = 0 To 4
  • Flag = False
  • While Flag = False
  • Choice = Console.ReadLine().ToLower()
  • If Choice = "vowel" Then
  • DataAccessed = PopVowel()
  • Letters = Letters & DataAccessed
  • Flag = True

Part 1(d)(i) — solution

  1. ElseIf Choice = "consonant" Then
  2. DataAccessed = PopConsonant()
  3. Letters = Letters & DataAccessed
  4. Flag = True
  5. VowelTop = 0
  6. ConsonantTop = 0
  7. Letters = ""
  8. Flag = False
  9. Flag = False
  10. while Flag == False:
  11. Choice = input("Vowel or Consonant").lower()
  12. if Choice == "vowel":
  13. DataAccessed = PopVowel()
  14. if DataAccessed != "No data":
  15. Letters = Letters + DataAccessed
  16. Flag = True

Python

#main
               VowelTop = 0
               ConsonantTop = 0
               ReadData()
               Letters = ""
               Flag = False

               for x in range(0, 5):
                  Flag = False
                  while Flag == False:
                     Choice = input("Vowel or Consonant").lower()
                     if Choice == "vowel":
                         DataAccessed = PopVowel()
                         if DataAccessed != "No data":
                            Letters = Letters + DataAccessed
                            Flag = True
                         else:
                            print("No vowels left")

 2023                                               Page 15 of 34

9618/42                                       Cambridge International AS & A Level – Mark Scheme       October/November 2023

Mark points

  • ElseIf Choice = "consonant" Then
  • DataAccessed = PopConsonant()
  • Letters = Letters & DataAccessed
  • Flag = True
  • VowelTop = 0
  • ConsonantTop = 0
  • Letters = ""
  • Flag = False
  • Flag = False
  • while Flag == False:
  • Choice = input("Vowel or Consonant").lower()
  • if Choice == "vowel":
  • DataAccessed = PopVowel()
  • if DataAccessed != "No data":
  • Letters = Letters + DataAccessed
  • Flag = True

Part 1(d)(i) — solution

  1. elif Choice == "consonant":
  2. DataAccessed = PopConsonant()
  3. if DataAccessed != "No data":
  4. Letters = Letters + DataAccessed
  5. Flag = True

Mark points

  • elif Choice == "consonant":
  • DataAccessed = PopConsonant()
  • if DataAccessed != "No data":
  • Letters = Letters + DataAccessed
  • Flag = True

Part 1(d)(ii) — solution

One mark showing input in order vowel, cons, cons, vowel, vowel. Output is then utxoe 1 e.g. 2023 Page 16 of 34 9618/42 Cambridge International AS & A Level – Mark Scheme October/November 2023

Mark points

  • Include the ideas shown in the solution above.

Question 2

Paper page 6 for Q2
Original paper page 6

Part 2(a)(i) — solution

  1. Function header with parameter
  2. Correct loop
  3. Modulus calculation
  4. Return of correct value at correct place
  5. Remainder of function correct

Visual Basic (VB.NET)

Function IterativeCalculate(Number As Integer)
                      Dim total As Integer = 0
                      Dim ToFind As Integer = Number
                      While Number <> 0
                         If ToFind Mod Number = 0 Then
                             total = total + Number
                         End If
                         Number = Number - 1
                      End While
                      Return total
                   End Function

 2023                                                       Page 17 of 34

9618/42                                      Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Function header with parameter
  • Correct loop
  • Modulus calculation
  • Return of correct value at correct place
  • Remainder of function correct

Part 2(a)(i) — solution

  1. Total = 0
  2. ToFind = Number
  3. while Number != 0:
  4. if ToFind % Number == 0:
  5. Total = Total + Number
  6. Number = Number - 1

Python

def IterativeCalculate(Number):
                  Total = 0
                  ToFind = Number
                  while Number != 0:
                     if ToFind % Number == 0:
                         Total = Total + Number
                     Number = Number - 1
                  return Total

Mark points

  • Total = 0
  • ToFind = Number
  • while Number != 0:
  • if ToFind % Number == 0:
  • Total = Total + Number
  • Number = Number - 1

Part 2(a)(ii) — solution

  1. Calling IterativeCalculate(10)
  2. Outputting return value

Visual Basic (VB.NET)

Sub Main(args As String())

                  Console.WriteLine(IterativeCalculate(10))
               End Sub

Python

print(IterativeCalculate(10))

Mark points

  • Calling IterativeCalculate(10)
  • Outputting return value

Part 2(a)(iii) — solution

One mark for screenshot showing 18 1 2023 Page 18 of 34 9618/42 Cambridge International AS & A Level – Mark Scheme October/November 2023

Mark points

  • Include the ideas shown in the solution above.

Part 2(b)(i) — solution

  1. IF Number = 0 THEN
  2. IF ToFind MODULUS Number = 0 THEN

Mark points

  • IF Number = 0 THEN
  • IF ToFind MODULUS Number = 0 THEN

Part 2(b)(i) — solution

  1. If Number = 0 Then
  2. If ToFind Mod Number = 0 Then
  3. if Number == 0:
  4. if ToFind % Number == 0:

Visual Basic (VB.NET)

Function RecursiveValue(Number As Integer, ToFind As Integer)
                     If Number = 0 Then
                        Return 0
                     Else
                        If ToFind Mod Number = 0 Then
                            Return Number + RecursiveValue(Number - 1, ToFind)
                        Else
                            Return RecursiveValue(Number - 1, ToFind)
                        End If
                     End If
                  End Function

Python

def RecursiveValue(Number, ToFind):
                  if Number == 0:
                     return 0
                  else:
                     if ToFind % Number == 0:
                         return Number + RecursiveValue(Number - 1, ToFind)
                     else:
                         return RecursiveValue(Number - 1, ToFind)

 2023                                               Page 20 of 34

9618/42                                      Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • If Number = 0 Then
  • If ToFind Mod Number = 0 Then
  • if Number == 0:
  • if ToFind % Number == 0:

Part 2(b)(ii) — solution

One mark for calling RecursiveValue(50,50)and outputting return value 1 Example program code: VB.NET Console.WriteLine(RecursiveValue(50,50)) Python print(RecursiveValue(50,50))

Visual Basic (VB.NET)

Console.WriteLine(RecursiveValue(50,50))

Python

print(RecursiveValue(50,50))

Mark points

  • Include the ideas shown in the solution above.

Part 2(b)(iii) — solution

One mark for screenshot showing 93 1 2023 Page 21 of 34 9618/42 Cambridge International AS & A Level – Mark Scheme October/November 2023

Mark points

  • Include the ideas shown in the solution above.

Question 3

Paper page 10 for Q3
Original paper page 10

Part 3(a)(i) — solution

  1. Class declaration
  2. Four attributes with correct data types
  3. Constructor header
  4. … taking 4 parameters
  5. Setting attributes to parameter values

Visual Basic (VB.NET)

Class Character
                  Private CharacterName As String
                  Private DateOfBirth As Date
                  Private Intelligence As Single
                  Private Speed As Integer

                   Sub New(CName, DBirth, Intell, SpeedP)
                      CharacterName = CName
                      DateOfBirth = DBirth

 2023                                                       Page 22 of 34

9618/42                                Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Class declaration
  • Four attributes with correct data types
  • Constructor header
  • … taking 4 parameters
  • Setting attributes to parameter values

Part 3(a)(i) — solution

  1. Intelligence = Intell
  2. Speed = SpeedP
  3. self.__CharacterName = CName
  4. self.__DateOfBirth = DBirth
  5. self.__Intelligence = Intell
  6. self.__Speed = SpeedP

Python

class Character:
                  #self.__CharacterName string
                  #self.__DateOfBirth date
                  #self.__Intelligence real
                  #self.__Speed integer

                  def __init__(self, CName, DBirth, Intell, SpeedP):
                     self.__CharacterName = CName
                     self.__DateOfBirth = DBirth
                     self.__Intelligence = Intell
                     self.__Speed = SpeedP

 2023                                               Page 23 of 34

9618/42                                     Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Intelligence = Intell
  • Speed = SpeedP
  • self.__CharacterName = CName
  • self.__DateOfBirth = DBirth
  • self.__Intelligence = Intell
  • self.__Speed = SpeedP

Part 3(a)(ii) — solution

  1. 1 get header with no parameter …
  2. … returning attribute
  3. Second correct get method

Visual Basic (VB.NET)

Function GetIntelligence()
                     Return Intelligence
                  End Function

                  Function GetName()
                     Return CharacterName
                  End Function

Python

def GetIntelligence(self):
                     return self.__Intelligence

                  def GetName(self):
                     return self.__CharacterName

 2023                                                    Page 24 of 34

9618/42                                      Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • 1 get header with no parameter …
  • … returning attribute
  • Second correct get method

Part 3(a)(iii) — solution

  1. Set header with 1 parameter …
  2. … assigns parameter to attribute

Visual Basic (VB.NET)

Sub SetIntelligence(NewValue)
                     Intelligence = NewValue
                  End Sub+

Python

def SetIntelligence(self, NewValue):
                     self.__Intelligence = NewValue

 2023                                                     Page 25 of 34

9618/42                                         Cambridge International AS & A Level – Mark Scheme                       October/November 2023

Mark points

  • Set header with 1 parameter …
  • … assigns parameter to attribute

Part 3(a)(iv) — solution

  1. Intelligence = Intelligence * 1.1
  2. self.__Intelligence = self.__Intelligence * 1.1

Visual Basic (VB.NET)

Overridable Sub Learn()
                      Intelligence = Intelligence * 1.1
                   End Sub

Python

def Learn(self):
                      self.__Intelligence = self.__Intelligence * 1.1

 2023                                                           Page 26 of 34

9618/42                                       Cambridge International AS & A Level – Mark Scheme                 October/November 2023

Mark points

  • Intelligence = Intelligence * 1.1
  • self.__Intelligence = self.__Intelligence * 1.1

Part 3(a)(v) — solution

  1. Method (function) header (and end where appropriate) no parameter, returning a calculated age
  2. Extracting attribute year of birth from date and subtracting from 2023

Visual Basic (VB.NET)

Function ReturnAge()
                  Return DateDiff(DateInterval.Year, DateOfBirth, #01/01/2023#)
               End Function

Python

def ReturnAge(self):
                      return 2023 - self.__DateOfBirth.year

 2023                                                       Page 27 of 34

9618/42                                    Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Method (function) header (and end where appropriate) no parameter, returning a calculated age
  • Extracting attribute year of birth from date and subtracting from 2023

Part 3(b)(i) — solution

  1. Creating new instance of Character with identifier FirstCharacter …
  2. … sending correct values as parameters

Visual Basic (VB.NET)

Sub Main(args As String())
                  Dim FirstCharacter As Character
                  FirstCharacter = New Character("Royal", #1/1/2019#, 70, 30)
               End Sub

Python

FirstCharacter = Character("Royal", datetime.datetime(2019, 1, 1), 70, 30)

 2023                                                   Page 28 of 34

9618/42                                         Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Creating new instance of Character with identifier FirstCharacter …
  • … sending correct values as parameters

Part 3(b)(ii) — solution

  1. Calling Learn() for FirstCharacter
  2. Calling ReturnAge() and outputting return value
  3. Outputting name and intelligence using gets with suitable message

Visual Basic (VB.NET)

FirstCharacter.Learn()
                       Console.WriteLine(FirstCharacter.GetName() & " is " & FirstCharacter.ReturnAge() &
               " years old and has intelligence " & FirstCharacter.GetIntelligence())

Python

FirstCharacter.Learn()
               print(FirstCharacter.GetName(), "is", FirstCharacter.ReturnAge(), "years old and has
               intelligence" , FirstCharacter.GetIntelligence())

   3(b(iii)    One mark for screenshot with Royal, 4 years, 77 intelligence e.g.                                        1

 2023                                                          Page 29 of 34

9618/42                                       Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Calling Learn() for FirstCharacter
  • Calling ReturnAge() and outputting return value
  • Outputting name and intelligence using gets with suitable message

Part 3(c)(i) — solution

  1. Class header inheriting from Character
  2. Declaring Element as string
  3. Constructor header taking 5 parameters …
  4. … calling parent constructor with the 4 parameters
  5. … assigning parameter to Element

Visual Basic (VB.NET)

Class MagicCharacter
                      Inherits Character
                      Private Element As String
                      Sub New(ElementP, CName, DBirth, Intell, SpeedP)
                         MyBase.New(CName, DBirth, Intell, SpeedP)
                         Element = ElementP
                      End Sub

                   End Class

 2023                                                          Page 30 of 34

9618/42                                Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Class header inheriting from Character
  • Declaring Element as string
  • Constructor header taking 5 parameters …
  • … calling parent constructor with the 4 parameters
  • … assigning parameter to Element

Part 3(c)(i) — solution

  1. self.__Element = ElementP

Python

class MagicCharacter(Character):
                  #self.__Element String

                  def __init__(self, ElementP, CName, DBirth, Intell, SpeedP):
                     super().__init__(CName, DBirth, Intell, SpeedP)
                     self.__Element = ElementP

 2023                                               Page 31 of 34

9618/42                                        Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • self.__Element = ElementP

Part 3(c)(ii) — solution

  1. Method header overriding parent method but no parameters
  2. Checking element value …
  3. … correct calculations with attribute intelligence and storing

Visual Basic (VB.NET)

Overrides Sub Learn()
                      If Element = "fire" Or Element = "water" Then
                         SetIntelligence(GetIntelligence() * 1.2)
                      ElseIf Element = "earth" Then
                         SetIntelligence(GetIntelligence() * 1.3)
                      Else
                         SetIntelligence(GetIntelligence() * 1.1)
                      End If

                   End Sub

 2023                                                         Page 32 of 34

9618/42                                    Cambridge International AS & A Level – Mark Scheme   October/November 2023

Mark points

  • Method header overriding parent method but no parameters
  • Checking element value …
  • … correct calculations with attribute intelligence and storing

Part 3(c)(ii) — solution

  1. if(self.__Element == "fire" or self.__Element == "water"):
  2. elif self.__Element == "earth":

Python

def Learn(self):
                     if(self.__Element == "fire" or self.__Element == "water"):
                        super().SetIntelligence(super().GetIntelligence() * 1.2)
                     elif self.__Element == "earth":
                        super().SetIntelligence(super().GetIntelligence() * 1.3)
                     else:
                        super().SetIntelligence(super().GetIntelligence() * 1.1)

Mark points

  • if(self.__Element == "fire" or self.__Element == "water"):
  • elif self.__Element == "earth":

Part 3(d)(i) — solution

  1. Declaring MagicCharacter with identifier FirstMagic …
  2. … with correct parameters

Visual Basic (VB.NET)

Dim FirstMagic As MagicCharacter
               FirstMagic = New MagicCharacter("fire", "Light", #3/3/2018#, 75, 22)

Python

FirstMagic = MagicCharacter("fire", "Light", datetime.datetime(2018, 3, 3), 75, 22)

 2023                                                   Page 33 of 34

9618/42                                       Cambridge International AS & A Level – Mark Scheme                       October/November 2023

Mark points

  • Declaring MagicCharacter with identifier FirstMagic …
  • … with correct parameters

Part 3(d)(ii) — solution

One mark for calling Learn() for FirstMagic and outputting all required data in appropriate message using gets. 1 Example program code: VB.NET FirstMagic.Learn() Console.WriteLine(FirstMagic.GetName() & " is " & FirstMagic.ReturnAge() & " years old and has intelligence " & FirstMagic.GetIntelligence()) Python FirstMagic.Learn() print(FirstMagic.GetName(), "is", FirstMagic.ReturnAge(), "years old and has intelligence", FirstMagic.GetIntelligence())

Visual Basic (VB.NET)

FirstMagic.Learn()
               Console.WriteLine(FirstMagic.GetName() & " is " & FirstMagic.ReturnAge() & " years old and
               has intelligence " & FirstMagic.GetIntelligence())

Python

FirstMagic.Learn()
               print(FirstMagic.GetName(), "is", FirstMagic.ReturnAge(), "years old and has intelligence",
               FirstMagic.GetIntelligence())

Mark points

  • Include the ideas shown in the solution above.

Part 3(d)(iii) — solution

One mark for screenshot e.g. 1 2023 Page 34 of 34

Mark points

  • Include the ideas shown in the solution above.