0% found this document useful (0 votes)
83 views31 pages

Mid Year Markscheme Answers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 31

Cambridge International Examinations

Cambridge International Advanced Subsidiary and Advanced Level

COMPUTER SCIENCE 9618/41_43

Paper 4 Practical May/June 2023

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.

GENERIC MARKING PRINCIPLE 1:


Marks must be awarded in line with:
 the specific content of the mark scheme or the generic level descriptors for the question
 the specific skills defined in the mark scheme or in the generic level descriptors for the question
 the standard of response required by a candidate as exemplified by the standardisation scripts.

GENERIC MARKING PRINCIPLE 2:


Marks awarded are always whole marks (not half marks, or other fractions).

GENERIC MARKING PRINCIPLE 3:


Marks must be awarded positively:
 marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond the scope of
the syllabus and mark scheme, referring to your Team Leader as appropriate
 marks are awarded when candidates clearly demonstrate what they know and can do
 marks are not deducted for errors
 marks are not deducted for omissions
 answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the question as
indicated by the mark scheme. The meaning, however, should be unambiguous.

GENERIC MARKING PRINCIPLE 4:


Rules must be applied consistently e.g. in situations where candidates have not followed instructions or in the application of generic level descriptors.

GENERIC MARKING PRINCIPLE 5:


Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may be limited
according to the quality of the candidate responses seen).

GENERIC MARKING PRINCIPLE 6:


Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or grade descriptors
in mind.

Page 2 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION

Question Answer Marks Guidance

1(a)(i) 1 mark for 1


 1D array with name DataArray with 25 elements of type Integer
Example program code:
Java
Integer[] DataArray = new Integer[25];

VB.NET
Dim DataArray(24) As Integer

or Dim DataArray(25) As Integer

Python
DataArray = [] #25 elements Integer

or DataArray = [0 for x in range(25)]

1(a)(ii) 1 mark each to max 4 4


 Opening file Data.txt to read
 Looping through all the 25/EOF …
 … reading line and appending into array
 Exception handling with appropriate output
 Closing the file
Example program code:
Java
Integer Counter = 0;
try{
Scanner Scanner1 = new Scanner(new File("Data.txt"));

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")

1(b)(i) 1 mark each 3


 Procedure header (and close where appropriate) with integer array parameter
Page 4 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION

 Looping and outputting each array element …


 …on one line
Example program code:
Java
public static void PrintArray(Integer[] DataArray){
String OutputData;
for(Integer X = 0; X < DataArray.length - 1; X++){
OutputData = OutputData + DataArray[X] + " ";
}
System.out.print(OutputData);
}
VB.NET
Sub PrintArray(DataArray)
Dim OutputData As String;
For x = 0 To DataArray.length - 1
OutputData = OutputData & DataArray(x) & " "
Next
Console.WriteLine(OutputData)
End Sub

Python
def PrintArray(DataArray):
for X in range(0, len(DataArray)):
print(DataArray[X])

1(b)(ii) 1 mark for calling PrintArray with the array as a parameter 1

Example program code:


Java
PrintArray(DataArray);

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)

1(b)(iii) 1 mark for screenshot 1

e.g.

1(c) 1 mark each 3


 Function header (and close where appropriate) taking array and search value as parameters
 Looping through each array element and keeping count of the number of times the parameter
appears // Python equivalent
 Returning the count value
Example program code:
Java
public static Integer LinearSearch(Integer[] DataArray, Integer DataToFind){
Integer Count = 0;
for(Integer x = 0; x < DataArray.length - 1; x++){
if(DataArray[x] == DataToFind){
Count++;
}
}
return Count;
}

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

Console.WriteLine("Enter a number to find ")


Dim DataToFind As Integer = -1
Do Until DataToFind >= 0 And DataToFind <= 100
DataToFind = Console.ReadLine()
Loop
Dim NumberTimes = LinearSearch(DataArray, DataToFind)
Console.WriteLine("The number " & DataToFind & " is found " & NumberTimes &
" times.")

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

2(a)(i) 1 mark each 5


 Class header (and close where appropriate)
 5 private attribute declarations
 Constructor header (and close where appropriate) taking 3 parameters
 Assigning ID, MaxSpeed and IncreaseAmount to parameters
 Assigning CurrentSpeed and HorizontalPosition to 0
Example program code:
VB.NET

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

Private CurrentSpeed As Integer


Private IncreaseAmount As Integer
Private HorizontalPosition As Integer

Sub New(IDP, MaxSpeedP, IncreaseAmountP)


ID = IDP
MaxSpeed = MaxSpeedP
CurrentSpeed = 0
IncreaseAmount = IncreaseAmountP
HorizontalPosition = 0
End Sub
End Class

Java
class Vehicle{
private String ID;
private Integer MaxSpeed;
private Integer CurrentSpeed;
private Integer IncreaseAmount;
private Integer HorizontalPosition;

public Vehicle(String IDP, Integer MaxSpeedP, Integer


IncreaseAmountP){
ID = IDP;
MaxSpeed = MaxSpeedP;
IncreaseAmount = IncreaseAmountP;
CurrentSpeed = 0;
HorizontalPosition = 0;
}}

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

def __init__(self, IDP, MaxSpeedP, IncreaseAmountP):


self.__ID = IDP
self.__MaxSpeed = MaxSpeedP
self.__IncreaseAmount = IncreaseAmountP
self.__CurrentSpeed = 0
self.__HorizontalPosition = 0
2(a)(ii) 1 mark each 3
 1 get function header (and end where appropriate) with no parameter …
 …returning attribute (without overwriting)
 3 further correct get methods

Example program code:


VB.NET
Function GetCurrentSpeed()
Return CurrentSpeed
End Function
Function GetIncreaseAmount()
Return IncreaseAmount
End Function
Function GetHorizontalPosition()
Return HorizontalPosition
End Function
Function GetMaxSpeed()
Return MaxSpeed
End Function

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

public Integer GetIncreaseAmount(){


return IncreaseAmount;
}
public Integer GetHorizontalPosition(){
return HorizontalPosition;
}
public Integer GetMaxSpeed(){
return MaxSpeed;
}

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

HorizontalPosition = HorizontalPosition + CurrentSpeed;


}
e.g. Python
def IncreaseSpeed(self):
self.__CurrentSpeed = self.__CurrentSpeed + self.__IncreaseAmount
if(self.__CurrentSpeed > self.__MaxSpeed):
self.__CurrentSpeed = self.__MaxSpeed
self.__HorizontalPosition = self.__HorizontalPosition +
self.__CurrentSpeed
2(b)(i) 1 mark each 5
 Class header (and end where appropriate) inheriting from Vehicle
 3 private attribute declarations
 Constructor (and end where appropriate) with 5 parameters
 Calling parent constructor with appropriate parameters
 Initialising vertical position to 0 and other parameters to attributes

Example program code:


VB.NET
Class Helicopter
Inherits Vehicle
Private VerticalPosition As Integer
Private VerticalChange As Integer
Private MaxHeight As Integer

Sub New(IDP, MaxSpeedP, IncreaseAmountP, VertChangeP, MaxHeightP)


MyBase.New(IDP, MaxSpeedP, IncreaseAmountP)
VerticalPosition = 0
VerticalChange = VertChangeP
MaxHeight = MaxHeightP

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;

public Helicopter(String IDP, Integer MaxSpeedP, Integer


IncreaseAmountP, Integer VertChangeP, Integer MaxHeightP){
super(IDP, MaxSpeedP, IncreaseAmountP);
VerticalPosition = 0;
VerticalChange = VertChangeP;
MaxHeight = MaxHeightP;
}}
Python
class Helicopter(Vehicle):
#VerticalPosition Integer
#VerticalChange Integer
#MaxHeight Integer

def __init__(self, IDP, MaxSpeedP, IncreaseAmountP, VertChangeP,


MaxHeightP):
Vehicle.__init__(self,IDP, MaxSpeedP, IncreaseAmountP)
self.__VerticalPosition = 0
self.__VerticalChange = VertChangeP
self.__MaxHeight = MaxHeightP

2(b)(ii) 1 mark each to max 4 4


 Procedure header (overriding where required) with no parameter

Page 14 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION

 Adding vertical change to vertical position …


 …limiting to maximum height
 Repeating/calling/using the code from original increase

Example program code:


VB.NET
Overrides Sub IncreaseSpeed()
VerticalPosition = VerticalPosition + VerticalChange
If VerticalPosition > MaxHeight Then
VerticalPosition = MaxHeight
End If
Me.SetCurrentSpeed(GetCurrentSpeed() + GetIncreaseAmount())
If Me.GetCurrentSpeed() > Me.GetMaxSpeed() Then
Me.SetCurrentSpeed(Me.GetMaxSpeed())
End If
Me.SetHorizontalPosition(Me.GetHorizontalPosition() +
Me.GetCurrentSpeed())
End Sub

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

public void OutputCurrentPosition(){


System.out.println("Current position = " + HorizontalPosition);
System.out.println("Current speed = " + CurrentSpeed);
}

public void OutputCurrentPosition(){


System.out.println("Current position = "
+super.GetHorizontalPosition());
System.out.println("Current speed = " + super.GetCurrentSpeed());
System.out.println("Current vertical position = " + VerticalPosition);
}
e.g. Python
def OutputCurrentPosition(self):
print("Current position = ", self.__HorizontalPosition)
print("Current speed = ", self.__CurrentSpeed)
def OutputCurrentPosition(self):
print("Current position = ", Vehicle.GetHorizontalPosition(self))
print("Current speed = ", Vehicle.GetCurrentSpeed(self))
print("Current verticalposition = ", self.__VerticalPosition)
2(d)(i) 1 mark each 5
 Instantiating an object of type Vehicle with correct parameters
 Instantiating an object of type Helicopter with correct parameters
 Calling IncreaseAmountSpeed twice for the car
 Calling IncreaseAmountSpeed twice for the helicopter
 Calling the output for both objects

Example program code:


VB.NET
Sub Main()
Dim Car As Vehicle
Car = New Vehicle("Tiger", 100, 20)

Page 17 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION

Dim Heli1 As Helicopter


Heli1 = New Helicopter("Lion", 350, 40, 3, 100)
Car.IncreaseAmountSpeed()
Car.IncreaseAmountSpeed()
OutputCurrentPosition(Car)
Console.WriteLine("")
Heli1.IncreaseAmountSpeed()
Heli1.IncreaseAmountSpeed()
OutputCurrentPosition(Heli1)
End Sub

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()

2(d)(ii) Screenshot of results e.g. 1

3(a) 1 mark each 3


 Global Animal array with 20 elements
 Global Colour array with 10 elements
 Global AnimalTopPointer and ColourTopPointer initialised to 0

Example program code:


Java
public static String[] Animal = new String[20];
public static String[] Colour = new String[10];
public static Integer AnimalTopPointer = 0;
public static Integer ColourTopPointer = 0;

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

Colour = [] #10 elements


global AnimalTopPointer
global ColourTopPointer
AnimalTopPointer = 0
ColourTopPointer = 0

3(b)(i) 1 mark each 3


 Function header (and close where appropriate) with parameter, checking if full and returning false
 If not full, inserting parameter value…
 …incrementing pointer and returning true

Example program code:


Java
public static Boolean PushAnimal(String DataToPush){
if(AnimalTopPointer == 20){
return false;
}else{
Animal[AnimalTopPointer] = DataToPush;
AnimalTopPointer++;
return true;
}
}

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

Example program code:


Java
public static String PopAnimal(){
String ReturnData;
if(AnimalTopPointer == 0){
return "";
}else{
ReturnData = Animal[AnimalTopPointer - 1];
AnimalTopPointer--;
return ReturnData;
}
}

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

Example program code:


Java
private static void ReadData(){
try{
Scanner Scanner1 = new Scanner(new File("AnimalData.txt"));
while(Scanner1.hasNextLine()){
PushAnimal(Scanner1.next());

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

3(b)(iv) 1 mark each 2


 PushColour function
 PopColour function

Example program code:


Java
public static Boolean PushColour(String DataToPush){
if(ColourTopPointer == 10){
return false;
}else{
Colour[ColourTopPointer] = DataToPush;
ColourTopPointer++;
return true;
}
}
public static String PopColour(){
String ReturnData;
if(ColourTopPointer == 0){
return "";
}else{
ReturnData = Colour[ColourTopPointer - 1];
ColourTopPointer--;
return ReturnData;
}
}

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

Example program code:


Java
private static void ReadData(){
try{
Scanner Scanner1 = new Scanner(new File("AnimalData.txt"));
while(Scanner1.hasNextLine()){
PushAnimal(Scanner1.next());
}
Scanner1.close();
}catch(FileNotFoundException ex){
System.out.println("No Animal file found");
}

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

Dim AnimalFileReader As New System.IO.StreamReader(AnimalFile)


Do Until AnimalFileReader.EndOfStream
PushAnimal(AnimalFileReader.ReadLine())
Loop
AnimalFileReader.Close()
Dim ColourFile As String = "ColourData.txt"
Dim ColourFileReader As New System.IO.StreamReader(ColourFile)
Do Until ColourFileReader.EndOfStream
PushColour(ColourFileReader.ReadLine())
Loop
ColourFileReader.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()

ColourFile = open("ColourData.txt", 'r')


for Line in ColourFile:
PushColour(Line)
ColourFile.close()
except IOError:
print("Could not find file")

Page 27 of 31
9618/41_43 AS & A Level Computer Science - Mark Scheme May/June 2023
PRE-STANDARDISATION

3(c) 1 mark each to max 5 5


 Procedure heading and outputting the colour and animal
 Using PopColour() and storing/checking result and using PopAnimal() and storing/checking
result
 Checking if no colour and outputting "No colour" …
 ….pushing the removed animal back onto the stack
 Checking if no animal and outputting "No animal" …
 …pushing the removed colour back onto the stack

Example program code:


Java
public static void OutputItem(){
String ColourReturned = PopColour();
String AnimalReturned = PopAnimal();
if(ColourReturned.equals("")){
System.out.println("No colour");
PushAnimal(AnimalReturned);
}else{
if(AnimalReturned.equals("")){
System.out.println("No animal");
PushColour(ColourReturned);
}else{
System.out.println("A " + ColourReturned + " " +
AnimalReturned);
}
}
}

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

3(d)(i) 1 mark for 1


 Calling ReadData() and calling OutputItem() 4 times

Example program code:


Java
public static void main(String args[]){
ReadData();
OutputItem();
OutputItem();
OutputItem();
OutputItem();
}

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

You might also like