Cambridge International AS & A Level: Computer Science 9618/41
Cambridge International AS & A Level: Computer Science 9618/41
Published
This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.
Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.
Cambridge International will not enter into discussions about these mark schemes.
Cambridge International is publishing the mark schemes for the May/June 2024 series for most
Cambridge IGCSE, Cambridge International A and AS Level and Cambridge Pre-U components, and some
Cambridge O Level components.
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 descriptions for a question. Each question paper and mark scheme will also comply with these
marking principles.
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.
Marks awarded are always whole marks (not half marks, or other fractions).
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.
Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level
descriptors.
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).
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.
VB.NET
Dim DataStored(19) As Integer
Dim NumberStored As Integer = 0
Python
global DataStored #integer
global NumberItems #Integer 20 items
VB.NET
Sub Initialise()
Console.WriteLine("How many numbers will you enter?")
Dim Quantity As Integer
Do
Quantity = Console.ReadLine()
Loop Until (Quantity > 0 And Quantity < 21)
For Count = 0 To Quantity - 1
Console.WriteLine("Enter number")
DataStored(NumberStored) = Console.ReadLine()
NumberStored += 1
Next
End Sub
1(b) Python
def Initialise():
global DataStored
global NumberItems
Valid = False
while(Valid == False):
NumberItems = int(input("How many numbers will you enter?")) #loop until < 20
if NumberItems > 0 and NumberItems< 21:
Valid = True
for Count in range(0, NumberItems):
DataStored.append(int(input("Enter number")))
VB.NET
NumberItems = 0
Initialise()
For X = 0 To NumberItems - 1
Console.WriteLine(DataStored(X))
Next
Python
NumberItems = 0
Initialise()
print(DataStored)
1(d)(i) Python
def BubbleSort():
global DataStored
global NumberItems
for Count in range(0, NumberItems):
for Count2 in range(0, NumberItems-1):
if DataStored[Count2] > DataStored[Count]:
DataStored[Count2], DataStored[Count] = DataStored[Count],
DataStored[Count2]
1(d)(ii) 1 mark for calling BubbleSort() and outputting array contents after 1
e.g.
VB.NET
BubbleSort()
For X = 0 To NumberStored - 1
Console.WriteLine(DataStored(X))
Next
e.g. Java
BubbleSort();
for(Integer X = 0; X < NumberItems; X++){
System.out.println(DataStored[X]);
}
e.g. Python
BubbleSort()
print(DataStored)
1(d)(iii) 1 mark for screenshot showing the inputs and the values in the correct order 1
e.g.
1(e)(i) VB.NET
Function BinarySearch(DataToFind)
Dim First As Integer = 0
Dim Last As Integer = NumberItems
Dim MidValue As Integer
While (First <= Last)
MidValue = (First + Last) / 2
If DataToFind = DataStored(MidValue) Then
Return MidValue
End If
If DataToFind < DataStored(MidValue) Then
Last = MidValue - 1
Else
First = MidValue + 1
End If
End While
Return -1
End Function
Python
def BinarySearch(DataToFind):
global DataStored
global NumberItems
First = 0
Last= NumberItems
while(First <= Last):
MidValue = int((First + Last) / 2)
if DataToFind == DataStored[MidValue]:
return MidValue
if DataToFind < DataStored[MidValue]:
Last = MidValue - 1
else:
First = MidValue + 1
return -1
VB.NET
Console.WriteLine("Enter a number to find")
Dim Search As Integer = Console.ReadLine()
Console.WriteLine(BinarySearch(Search))
Python
Search = int(input("Enter a number to find"))
print(BinarySearch(Search))
Test 2
public Tree(String Name, Integer HGrowth, Integer MaxH, Integer MaxW, String
PEvergreen){
TreeName = Name;
HeightGrowth = HGrowth;
MaxWidth = MaxW;
MaxHeight = MaxH;
Evergreen = PEvergreen;
}}
2(a)(i) VB.NET
Class Tree
Private TreeName As String
Private HeightGrowth As Integer
Private MaxHeight As Integer
Private MaxWidth As Integer
Private Evergreen As String
Sub New(Name, HGrowth, MaxH, MaxW, PEvergreen)
TreeName = Name
HeightGrowth = HGrowth
MaxHeight = MaxH
MaxWidth = MaxW
Evergreen = PEvergreen
End Sub
End Class
Python
class Tree:
def __init__(self, Name, HGrowth, MaxH, MaxW, PEvergreen):
self.__TreeName = Name
self.__HeightGrowth = HGrowth
self.__MaxHeight = MaxH
self.__MaxWidth = MaxW
self.__Evergreen = PEvergreen
2(a)(ii) VB.NET
Function GetTreeName()
Return TreeName
End Function
Function GetMaxHeight()
Return MaxHeight
End Function
Function GetMaxWIdth()
Return MaxWidth
End Function
Function GetGrowth()
Return HeightGrowth
End Function
Function GetEvergreen()
Return Evergreen
End Function
Python
def GetTreeName(self):
return self.__TreeName
def GetMaxHeight(self):
return self.__MaxHeight
def GetMaxWidth(self):
return self.__MaxWidth
def GetGrowth(self):
return self.__HeightGrowth
def GetEvergreen(self):
return self.__Evergreen
}catch(FileNotFoundException e){
System.out.println("File not found");
}
return TreeData;
}
2(b) VB.NET
Function ReadData()
Dim TreeObjects(10) As Tree
Dim TextFile As String = "Trees.txt"
try
Dim FileReader As New System.IO.StreamReader(TextFile)
Dim TreeData(10) As String
Dim TreeSplit() As String
For Count = 0 To 8
TreeData(Count) = FileReader.ReadLine()
Next Count
FileReader.Close()
For X = 0 To 8
TreeSplit = TreeData(X).Split(",")
TreeObjects(X) = New Tree(TreeSplit(0), Integer.Parse(TreeSplit(1)),
Integer.Parse(TreeSplit(2)), Integer.Parse(TreeSplit(3)), TreeSplit(4))
Next X
Catch ex As Exception
Console.WriteLine ("invalid file")
End Try
Return TreeObjects
End Function
2(b) Python
def ReadData():
TreeObjects=[]
try:
File = open("Trees.txt")
TreeData = []
TreeData = File.read().split("\n")
SplitTrees = []
for Item in TreeData:
SplitTrees.append(Item.split(","))
File.close()
for Item in SplitTrees:
TreeObjects.append(Tree(Item[0],int(Item[1]),int(Item[2]),int(Item[3]),Item[4]))
except IOError:
print ("invalid file")
return TreeObjects
e.g.
Java
public static void PrintTrees(Tree TreeItem){
String Final = "does not lose its leaves";
if((TreeItem.GetEvergreen()).compareTo("No") == 0){
Final = "loses its leaves each year";
}
System.out.println(TreeItem.GetTreeName() + " has a maximum height " +
TreeItem.GetMaxHeight() + " a maximum width " + TreeItem.GetMaxWidth() + " and grows " +
TreeItem.GetGrowth() + " cm a year. It " + Final);
}
VB.NET
Sub PrintTrees(Item)
Dim Final As String = "does not lose its leaves"
If (Item.GetEvergreen() = "No") Then
Final = "loses its leaves each year"
End If
Console.WriteLine(Item.GetTreeName() & " has a maximum height " &
Item.GetMaxHeight() & " a maximum width " & Item.GetMaxWidth() & " and grows " &
Item.GetGrowth() & "cm a year. It" & Final)
End Sub
2(c) Python
def PrintTrees(Item):
e.g.
Java
Tree[] TreeData = new Tree[20];
TreeData = ReadData();
PrintTrees(TreeData[0]);
VB.NET
Sub Main(args As String())
Dim TreeObjects(10) As Tree
TreeObjects = ReadData()
PrintTrees(Treeobjects(0))
End Sub
Python
TreeObjects = ReadData()
PrintTrees(TreeObjects[0])
e.g.
Java
public static void ChooseTree(Tree[] Trees){
Scanner scanner = new Scanner(System.in);
System.out.println("Do you want a tree that loses its leaves (enter lose), or keeps
its leaves (enter keep)") ;
String Evergreen = (scanner.nextLine());
System.out.println("What is the maximum tree height in cm");
Integer MaxHeight = Integer.parseInt(scanner.nextLine());
System.out.println("What is the maximum tree width in cm");
Integer MaxWidth = Integer.parseInt(scanner.nextLine());
Tree[] Options = new Tree[20];
String keep;
Tree Selected;
Boolean Valid = false;
if(((Evergreen.toLowerCase()).compareTo("keep") == 0) ||
((Evergreen.toLowerCase()).compareTo("keep leaves") == 0) ||
((Evergreen.toLowerCase()).compareTo("keeps its leaves") == 0)){
keep = "Yes";
}else{
keep = "No";
}
Integer Counter = 0;
for(Integer X = 0; X < 9; X++){
VB.NET
Sub ChooseTree(Trees)
Console.WriteLine("Do you want a tree that loses its leaves (enter lose), or keeps
its leaves (enter keep)")
Dim Evergreen As String = Console.ReadLine()
Console.WriteLine("What is the maximum tree height in cm")
Dim MaxHeight As Integer = Console.ReadLine()
Console.WriteLine("What is the maximum tree width in cm")
Dim MaxWidth As Integer = Console.ReadLine()
Dim Options(0 To 9) As Tree
Dim keep As String
Dim Valid As Boolean
Dim Selected As Tree
If Evergreen.ToLower() = "keep" Or Evergreen.ToLower() = "keep leaves" Or
Evergreen.ToLower() = "keeps its leaves" Then
keep = "Yes"
Else
keep = "No"
2(e)(i) End If
Dim count As Integer = 0
For x = 0 To 8
If Trees(x).GetMaxHeight() <= MaxHeight And Trees(x).GetMaxWidth() <= MaxWidth
And keep = Trees(x).GetEvergreen() Then
Options(count) = Trees(x)
PrintTrees(Trees(x))
count = count + 1
End If
Next x
If count = 0 Then
Console.WriteLine("No suitable trees")
End If
End Sub
Python
def ChooseTree(Trees):
Evergreen = input("Do you want a tree that loses its leaves (enter lose), or keeps its
leaves (enter keep)")
MaxHeight = int(input("What is the maximum tree height in cm"))
MaxWidth = int(input("What is the maximum tree width in cm"))
Options = []
if Evergreen.lower() == "keep" or Evergreen.lower() == "keep leaves" or
Evergreen.lower() == "keeps its leaves":
keep = "Yes"
else:
keep = "No"
for Item in Trees:
2(e)(ii) Java
Integer Start;
Float Height;
Float Growth;
Float Years;
while(Valid == false){
System.out.println("Enter the name of the tree you want");
String Choice = scanner.nextLine();
for(Integer X = 0; X < Counter; X++){
if((Options[X].GetTreeName()).compareTo(Choice)==0){
Valid = true;
Selected = Options[X];
System.out.println("Enter the height of the tree you would like to start
with in cm");
Start = Integer.parseInt(scanner.nextLine());
Height = (Selected.GetMaxHeight()).floatValue();
Growth = (Selected.GetGrowth()).floatValue();
Years = (Height - Start) / Growth;
System.out.println("Your tree should be full height in approximately "+
Years + " years");
}
}
}
Python:
Valid = False
while Valid == False:
Choice = input("Enter the name of the tree you want")
for Item in Options:
if Item.GetTreeName() == Choice:
Valid = True
Selected = Item
Start = int(input("Enter the height of the tree you would like to start with in
cm"))
Years = (Selected.GetMaxHeight() - Start)/Selected.GetGrowth()
print("Your tree should be full height in approximately", Years,"years")
Python
global QueueData
global QueueHead
global QueueTail
QueueData = []
for x in range(0, 20):
QueueData.append("")
QueueHead = -1
QueueTail = -1
3(b) Python
def Enqueue(DataToInsert):
global QueueData
global QueueHead
global QueueTail
if QueueTail == 19:
return False
elif QueueHead == -1:
QueueHead = 0
QueueTail = QueueTail + 1
QueueData.append(DataToInsert)
return True
3(c) Python
def Dequeue():
global QueueData
global QueueHead
global QueueTail
if QueueHead < 0 or QueueHead > 20 or QueueHead > QueueTail:
return False
else:
QueueHead = QueueHead + 1
return QueueData[QueueHead-1]
VB.NET
Sub StoreItems()
End Sub
3(d)(i) Python
def StoreItems():
global QueueData
global QueueHead
global QueueTail
Count = 0
for X in range(0, 10):
Data = input("Enter data")
Total= int(Data[0]) + int(Data[1]) * 3 + int(Data[2]) + int(Data[3]) * 3 +
int(Data[4]) + int(Data[5]) * 3
Total = int(Total / 10)
if((Total == 10 and Data[6] == "X") or (Total == int(Data[6]))):
Result = Enqueue(Data[0:6])
if(Result == True):
print("Inserted item")
else:
print("Queue full")
else:
Count = Count + 1
End Sub
3(d)(ii) Python
QueueData = []
for x in range(0, 20):
QueueData.append("")
QueueHead = -1
QueueTail = -1
StoreItems()
Value = Dequeue()
if Value == False:
print("No data items")
else:
print("Item code", Value)