Mid Year Markscheme Answers
Mid Year Markscheme Answers
Mid Year Markscheme Answers
MARK SCHEME
Maximum Mark : 75
[Turn over
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Cambridge International Examinations – Generic Marking Principles
These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the specific content of
the mark scheme or generic level descriptors for a question. Each question paper and mark scheme will also comply with these marking principles.
Page 2 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
VB.NET
Dim DataArray(24) As Integer
Python
DataArray = [] #25 elements Integer
Page 3 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
while(Scanner1.hasNextLine()){
DataArray[Counter] = Integer.parseInt(Scanner1.next());
Counter++;
}
Scanner1.close();
}catch(FileNotFoundException ex){
System.out.println("No data file found");
}
VB.NET
try
Dim DataReader As New System.IO.StreamReader("Data.txt")
Dim X As Integer = 0
Do Until DataReader.EndOfStream
DataArray(X) = DataReader.ReadLine()
X = X + 1
Loop
DataReader.Close()
Catch ex As Exception
Console.WriteLine("Invalid file")
End Try
Python
try:
DataFile = open("Data.txt",'r')
for Line in DataFile:
DataArray.append(int(Line))
DataFile.close()
except IOError:
print("Could not find file")
Python
def PrintArray(DataArray):
for X in range(0, len(DataArray)):
print(DataArray[X])
Page 5 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
VB.NET
PrintArray(DataArray)
Python
PrintArray(DataArray)
e.g.
VB.NET
Function LinearSearch(DataArray, DataToFind)
Dim Count As Integer = 0
Page 6 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
For x = 0 To DataArray.length - 1
If DataArray(x) = DataToFind Then
Count = Count + 1
End If
Next
Return Count
End Function
Python
def LinearSearch(DataArray, DataToFind):
Count = 0
for X in range(0, len(DataArray)):
if(DataArray[X] == DataToFind):
Count +=1
return Count
1(d)(i) 1 mark each 4
Prompt and reading input …
…with validation for whole number between 0 and 100 inclusive
Calling LinearSearch() with array and data input storing/using return value
Output of suitable message with values
Example program code:
Java
System.out.println("Enter a number to find");
Integer DataToFind = -1;
Scanner NewScanner = new Scanner(System.in);
while(DataToFind < 0 || DataToFind > 100){
DataToFind = Integer.parseInt(NewScanner.nextLine());
}
Integer NumberTimes = LinearSearch(DataArray, DataToFind);
System.out.println("The number " + DataToFind + " is found " + NumberTimes +
" times");
VB.NET
Page 7 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Python
DataToFind = int(input("Enter a number to find "))
while DataToFind < 0 or DataToFind > 100:
DataToFind = int(input("Enter a number to find "))
NumberTimes = LinearSearch(DataArray, DataToFind)
print("The number", DataToFind, "is found", NumberTimes, "times")
1(d)(ii) 1 mark for screenshot e.g. 1
Class Vehicle
Private ID As String
Private MaxSpeed As Integer
Page 8 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Java
class Vehicle{
private String ID;
private Integer MaxSpeed;
private Integer CurrentSpeed;
private Integer IncreaseAmount;
private Integer HorizontalPosition;
Python
class Vehicle:
#self.__ID string
#self.__MaxSpeed integer
#self.__CurrentSpeed integer
Page 9 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
#self.__IncreaseAmount integer
#self.__HorizontalPosition
Java
public Integer GetCurrentSpeed(){
return CurrentSpeed;
}
Page 10 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Python
def GetCurrentSpeed(self):
return self.__CurrentSpeed
def GetIncreaseAmount(self):
return self.__IncreaseAmount
def GetHorizontalPosition(self):
return self.__HorizontalPosition
def GetMaxSpeed(self):
return self.__MaxSpeed
2(a)(iii) 1 mark each 3
1 set procedure (and end where appropriate) taking parameter …
… assigns parameter to the attribute (without overriding)
Second correct set method
Example program code:
VB.NET
Sub SetCurrentSpeed(CSp)
CurrentSpeed = CSp
End Sub
Sub SetHorizontalPosition(HPP)
HorizontalPosition = HPP
End Sub
Java
public void SetCurrentSpeed(Integer CSP){
Page 11 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
CurrentSpeed = CSP;
}
public void SetHorizontalPosition(Integer HPP){
HorizontalPosition = HPP;
}
e.g. Python
def SetCurrentSpeed(self, CSP):
self.__CurrentSpeed = CSP
def SetHorizontalPosition(self, HPP):
self.__HorizontalPosition = HPP
2(a)(iv) 1 mark each 3
Procedure header (and close where appropriate) with no parameter and adding IncreaseAmount
to current speed
Checking if max speed is exceeded and limiting to max speed (remove increase or assign
maximum)
Adding updated current speed to horizontal position
Example program code:
VB.NET
Sub IncreaseSpeed()
CurrentSpeed = CurrentSpeed + IncreaseAmount
If CurrentSpeed > MaxSpeed Then
CurrentSpeed = MaxSpeed
End If
HorizontalPosition = HorizontalPosition + CurrentSpeed
End Sub
Java
public void IncreaseSpeed(){
CurrentSpeed = CurrentSpeed + IncreaseAmount;
if(CurrentSpeed > MaxSpeed){
CurrentSpeed = MaxSpeed;
}
Page 12 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
End Sub
Page 13 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
End Class
Java
class Helicopter extends Vehicle{
private Integer VerticalPosition;
private Integer VerticalChange;
private Integer MaxHeight;
Page 14 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Java
public void IncreaseSpeed(){
VerticalPosition = VerticalPosition + VerticalChange;
if(VerticalPosition > MaxHeight){
VerticalPosition = MaxHeight;
}
super.SetCurrentSpeed(super.GetCurrentSpeed() +
super.GetIncreaseAmount());
if(super.GetCurrentSpeed() > super.GetMaxSpeed()){
super.SetCurrentSpeed(super.GetMaxSpeed());
}
super.SetHorizontalPosition(super.GetHorizontalPosition() +
super.GetCurrentSpeed());
}
Page 15 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Python
def IncreaseSpeed(self):
self.__VerticalPosition = self.__VerticalPosition +
self.__VerticalChange
if(self.__VerticalPosition > self.__MaxHeight):
self.__VerticalPosition = MaxHeight
Vehicle.SetCurrentSpeed(self, Vehicle.GetCurrentSpeed(self) +
Vehicle.GetIncreaseAmount(self))
if(Vehicle.GetCurrentSpeed(self) > Vehicle.GetMaxSpeed(self)):
Vehicle.SetCurrentSpeed(self, Vehicle.GetMaxSpeed(self));
Vehicle.SetHorizontalPosition(self, Vehicle.GetHorizontalPosition(self)
+ Vehicle.GetCurrentSpeed(self))
2(c) 1 mark each to max 3 3
Suitable method/procedure heading (and end where appropriate) and outputting horizontal position
and current speed
Checking if Vehicle or Helicopter // overriding methods in each class for output …
… outputting vertical position only if helicopter with appropriate message
Using correct get methods throughout // calling parent methods
Example program code:
VB.NET
Sub OutputCurrentPosition(ObjectToOutput)
Console.WriteLine("Current position = " &
ObjectToOutput.GetHorizontalPosition())
Console.WriteLine("Current speed = " &
ObjectToOutput.GetCurrentSpeed())
If TypeOf ObjectToOutput Is Helicopter Then
Console.WriteLine("Current vertical position = " &
ObjectToOutput.GetVerticalPosition())
End If
End Sub
Page 16 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Java
Page 17 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Java
public static void main(String args[]){
Vehicle Car = new Vehicle("Tiger", 100, 20);
Helicopter Heli1 = new Helicopter("Lion", 350, 40, 3, 100);
Car.IncreaseAmountSpeed();
Car.IncreaseAmountSpeed();
Car.OutputCurrentPosition();
System.out.println("");
Heli1.IncreaseAmountSpeed();
Heli1.IncreaseAmountSpeed();
Heli1.OutputCurrentPosition();
}
Python
#main
Car = Vehicle("Tiger", 100, 20)
Heli1 = Helicopter("Lion", 350, 40, 3, 100)
Car.IncreaseAmountSpeed()
Car.IncreaseAmountSpeed()
Car.OutputCurrentPosition()
print("")
Heli1.IncreaseAmountSpeed()
Heli1.IncreaseAmountSpeed()
Page 18 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Heli1.OutputCurrentPosition()
VB.NET
Dim Animal(0 to 19) As String
Dim Colour(0 to 9) As String
Dim AnimalTopPointer As Integer = 0
Dim ColourTopPointer As Integer = 0
Python
Animal = [] #20 elements
Page 19 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
VB.NET
Function PushAnimal(DataToPush)
If AnimalTopPointer = 20 Then
Return False
Else
Animal(AnimalTopPointer) = DataToPush
AnimalTopPointer = AnimalTopPointer + 1
Return True
End If
End Function
Page 20 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Python
def PushAnimal(DataToPush):
global AnimalTopPointer
global ColourTopPointer
if AnimalTopPointer == 20:
return False
else:
Animal.append(DataToPush)
AnimalTopPointer +=1
return True
3(b)(ii) 1 mark each 3
Procedure header (and end where appropriate) with no parameter
Checking if empty and returning empty string
If not empty returning the top data item and decrementing pointer
VB.NET
Function PopAnimal()
Dim ReturnData As String
If AnimalTopPointer = 0 Then
Page 21 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Return ""
Else
ReturnData = Animal(AnimalTopPointer - 1)
AnimalTopPointer = AnimalTopPointer - 1
Return ReturnData
End If
End Function
Python
def PopAnimal():
global AnimalTopPointer
global ColourTopPointer
if AnimalTopPointer == 0:
return ""
else:
ReturnData = Animal[AnimalTopPointer - 1]
AnimalTopPointer -=1
return ReturnData
3(b)(iii) 1 mark 5
Procedure header (and close where appropriate) and opening correct file for read
Looping until end of file // looping until all animal names read in
Calling PushAnimal() with each animal name
Closing the file
Exception handling with appropriate error message
Page 22 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
}
Scanner1.close();
}catch(FileNotFoundException ex){
System.out.println("No Animal file found");
}
}
VB.NET
Sub ReadData()
try
Dim AnimalFile As String = "AnimalData.txt"
Dim AnimalFileReader As New System.IO.StreamReader(AnimalFile)
Do Until AnimalFileReader.EndOfStream
PushAnimal(AnimalFileReader.ReadLine())
Loop
AnimalFileReader.Close()
Catch ex As Exception
Console.WriteLine("Invalid file")
End Try
End Sub
Python
def ReadData():
try:
global AnimalTopPointer
global ColourTopPointer
AnimalFile = open("AnimalData.txt", 'r')
for Line in AnimalFile:
PushAnimal(Line)
AnimalFile.close()
except IOError:
print("Could not find file")
Page 23 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
VB.NET
Function PushColour(DataToPush)
If ColourTopPointer = 10 Then
Return False
Else
Colour(ColourTopPointer) = DataToPush
Page 24 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
ColourTopPointer = ColourTopPointer + 1
Return True
End If
End Function
Function PopColour()
Dim ReturnData As String
If ColourTopPointer = 0 Then
Return ""
Else
ReturnData = Colour(ColourTopPointer - 1)
ColourTopPointer = ColourTopPointer - 1
Return ReturnData
End If
End Function
Python
def PushColour(DataToPush):
global AnimalTopPointer
global ColourTopPointer
if ColourTopPointer == 10:
return False
else:
Colour.append(DataToPush)
ColourTopPointer +=1
return True
def PopColour():
global AnimalTopPointer
global ColourTopPointer
if ColourTopPointer == 0:
return ""
else:
ReturnData = Colour[ColourTopPointer - 1]
ColourTopPointer -=1
Page 25 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
return ReturnData
3(b)(v) 1 mark each 2
Opening ColourData.txt to read, reading until EOF, closing file
Using PushColour() to store each item read in
try{
Scanner Scanner2 = new Scanner(new File("ColourData.txt"));
while(Scanner2.hasNextLine()){
PushColour(Scanner2.next());
}
Scanner2.close();
}catch(FileNotFoundException ex){
System.out.println("No Colour file found");
}
}
VB.NET
Sub ReadData()
try
Dim AnimalFile As String = "AnimalData.txt"
Page 26 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
End Sub
Python
def ReadData():
try:
global AnimalTopPointer
global ColourTopPointer
AnimalFile = open("AnimalData.txt", 'r')
for Line in AnimalFile:
PushAnimal(Line)
AnimalFile.close()
Page 27 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
VB.NET
Sub OutputItem()
Dim ColourReturned As String = PopColour()
Dim Animalreturned As String = PopAnimal()
If ColourReturned = "" Then
Page 28 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Console.WriteLine("No colour")
PushAnimal(AnimalReturned)
Else
If Animalreturned = "" Then
Console.WriteLine("No animal")
PushColour(ColourReturned)
Else
Console.WriteLine("A " & ColourReturned & " " & Animalreturned)
End If
End If
End Sub
Python
def OutputItem():
global AnimalTopPointer
global ColourTopPointer
ColourReturned = PopColour()
AnimalReturned = PopAnimal()
if ColourReturned == "":
print("No colour")
PushAnimal(AnimalReturned)
else:
if AnimalReturned == "":
print("No animal")
PushColour(ColourReturned)
else:
print("A", ColourReturned, AnimalReturned)
Page 29 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
VB.NET
Sub Main()
ReadData()
OutputItem()
OutputItem()
OutputItem()
OutputItem()
End Sub
Python
ReadData()
OutputItem()
OutputItem()
OutputItem()
OutputItem()
3(d)(ii) 1 mark for output 1
e.g.
Page 30 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION
Page 31 of 31