Question 1

Part 1(a) — solution
- declaration of at least 1 array with appropriate identifier
- … 11 elements (and appropriate data type(s))
Visual Basic (VB.NET)
Dim FileData(0 To 9, 0 To 1) As String
Python
FileData = [[""] *2 for i in range(11)] #string 2022 Page 4 of 34 9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- declaration of at least 1 array with appropriate identifier
- … 11 elements (and appropriate data type(s))
Part 1(b) — solution
- procedure declaration (and end)
- Opening the text file (to read)
- Looping 10 times // looping until end of file (e.g. 10 pairs of data)
- Reading in each pair of lines …
- … storing player name and score in data structure(s)
- closing the file
- Try and catch on file handling …
- … with suitable output
Mark points
- procedure declaration (and end)
- Opening the text file (to read)
- Looping 10 times // looping until end of file (e.g. 10 pairs of data)
- Reading in each pair of lines …
- … storing player name and score in data structure(s)
- closing the file
- Try and catch on file handling …
- … with suitable output
Part 1(b) — solution
- Filename = "HighScore.txt"
- File = open(Filename, 'r')
- FileData[x][0] = File.readline()[:3]
- FileData[x][1] = File.readline()
- Dim Textfile As String = "HighScore.txt"
- Dim DataEntered As Integer = 0
- FileData(DataEntered, 0) = FileReader.ReadLine()
- FileData(DataEntered, 1) = FileReader.ReadLine()
- DataEntered = DataEntered + 1
Visual Basic (VB.NET)
Sub ReadHighScores()
Dim Textfile As String = "HighScore.txt"
Dim FileReader As New System.IO.StreamReader(textfile)
Dim DataEntered As Integer = 0
While FileReader.Peek <> -1 and DataEntered < 10
FileData(DataEntered, 0) = FileReader.ReadLine()
FileData(DataEntered, 1) = FileReader.ReadLine()
DataEntered = DataEntered + 1
End While
FileReader.Close()
End Sub
2022 Page 6 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Python
def ReadHighScores():
Filename = "HighScore.txt"
File = open(Filename, 'r')
for x in range(0, 10):
FileData[x][0] = File.readline()[:3]
FileData[x][1] = File.readline()
File.close
Mark points
- Filename = "HighScore.txt"
- File = open(Filename, 'r')
- FileData[x][0] = File.readline()[:3]
- FileData[x][1] = File.readline()
- Dim Textfile As String = "HighScore.txt"
- Dim DataEntered As Integer = 0
- FileData(DataEntered, 0) = FileReader.ReadLine()
- FileData(DataEntered, 1) = FileReader.ReadLine()
- DataEntered = DataEntered + 1
Part 1(c) — solution
- procedure heading and end
- looping through all data structure elements
- outputting player name, space, score. Each player must start on a new line
Visual Basic (VB.NET)
Sub OutputHighScores ()
For x = 0 To 10
Console.WriteLine(FileData(x, 0) & " " & FileData(x,1))
Next
End Sub
2022 Page 7 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Python
def OutputHighScores ():
for x in range(0, 11):
Output = FileData[x][0] + " " + FileData[x][1]
print(Output)
Mark points
- procedure heading and end
- looping through all data structure elements
- outputting player name, space, score. Each player must start on a new line
Part 1(d)(i) — solution
- (Main program) calls ReadHighScores()
- … then calls OutputHighScores()
Visual Basic (VB.NET)
Sub Main()
ReadHighScores()
OutputHighScore()
Console.ReadLine()
End Sub
2022 Page 8 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Python
ReadHighScores()
OutputHighScore()
Mark points
- (Main program) calls ReadHighScores()
- … then calls OutputHighScores()
Part 1(d)(ii) — solution
Mark points
- Include the ideas shown in the solution above.
Part 1(e)(i) — solution
- Read in a username and score
- Validate username input (3-characters, or just selecting the first 3 characters if there are definitely 3 characters)
- Validate score input (integer (cast) between 1 and 100 000 inclusive)
Python
Username = "ABCD"
while len(Username) != 3:
Username = input("Enter your Username")
score = -1
while Score < 1 or Score > 100000:
Score = int(input("Enter score"))
2022 Page 10 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- Read in a username and score
- Validate username input (3-characters, or just selecting the first 3 characters if there are definitely 3 characters)
- Validate score input (integer (cast) between 1 and 100 000 inclusive)
Part 1(e)(i) — solution
- Username = "ABCD"
- Username = Console.ReadLine()
- Score = -1
- Score = Console.ReadLine()
Visual Basic (VB.NET)
Console.WriteLine("Enter Username")
Username = "ABCD"
While Username.length <> 3
Username = Console.ReadLine()
End While
Score = -1
While Score < 1 Or Score > 100000
Console.WriteLine("Enter score")
Score = Console.ReadLine()
End While
2022 Page 11 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- Username = "ABCD"
- Username = Console.ReadLine()
- Score = -1
- Score = Console.ReadLine()
Part 1(e)(ii) — solution
- procedure declaration (and close where appropriate) taking 1 string and 1 integer parameter
- looping through each array element
- … finding the position to input the score
- storing the array data in the correct position
- storing the name and score in the correct position
Mark points
- procedure declaration (and close where appropriate) taking 1 string and 1 integer parameter
- looping through each array element
- … finding the position to input the score
- storing the array data in the correct position
- storing the name and score in the correct position
Part 1(e)(ii) — solution
- Temp1 = FileData[x][0]
- Temp2 = FileData[x][1]
- FileData[x][0] = Username
- FileData[x][1] = Score
- Count = x+1
- Second1 = FileData[Count][0]
- Second2 = FileData[Count][1]
- FileData[Count][0] = Temp1
- FileData[Count][1] = Temp2
- Temp1 = Second1
- Temp2 = Second2
- Count = Count + 1
Python
def Arrange(Username, Score):
for x in range(0, 10):
if Score > FileData[x][1]:
Temp1 = FileData[x][0]
Temp2 = FileData[x][1]
FileData[x][0] = Username
FileData[x][1] = Score
Count = x+1
while(Count < 10):
Second1 = FileData[Count][0]
Second2 = FileData[Count][1]
FileData[Count][0] = Temp1
FileData[Count][1] = Temp2
Temp1 = Second1
Temp2 = Second2
Count = Count + 1
break;
2022 Page 13 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- Temp1 = FileData[x][0]
- Temp2 = FileData[x][1]
- FileData[x][0] = Username
- FileData[x][1] = Score
- Count = x+1
- Second1 = FileData[Count][0]
- Second2 = FileData[Count][1]
- FileData[Count][0] = Temp1
- FileData[Count][1] = Temp2
- Temp1 = Second1
- Temp2 = Second2
- Count = Count + 1
Part 1(e)(ii) — solution
- For x = 0 To 9
- Temp1 = FileData(x, 0)
- Temp2 = FileData(x, 1)
- FileData(x, 0) = Username
- FileData(x, 1) = Score.ToString
- For Count = x + 1 To 9
- Second1 = FileData(Count, 0)
- Second2 = FileData(Count, 1)
- FileData(Count, 0) = Temp1
- FileData(Count, 1) = Temp2
- Temp1 = Second1
- Temp2 = Second2
- x = 10
Visual Basic (VB.NET)
Sub Arrange(Username, Score)
Dim Temp1 As String
Dim Temp2 As String
Dim Second1 As String
Dim Second2 As String
For x = 0 To 9
If Score > Integer.Parse(FileData(x, 1)) Then
Temp1 = FileData(x, 0)
Temp2 = FileData(x, 1)
FileData(x, 0) = Username
FileData(x, 1) = Score.ToString
For Count = x + 1 To 9
Second1 = FileData(Count, 0)
Second2 = FileData(Count, 1)
FileData(Count, 0) = Temp1
FileData(Count, 1) = Temp2
Temp1 = Second1
Temp2 = Second2
x = 10
Next
End If
Next
End Sub
2022 Page 14 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- For x = 0 To 9
- Temp1 = FileData(x, 0)
- Temp2 = FileData(x, 1)
- FileData(x, 0) = Username
- FileData(x, 1) = Score.ToString
- For Count = x + 1 To 9
- Second1 = FileData(Count, 0)
- Second2 = FileData(Count, 1)
- FileData(Count, 0) = Temp1
- FileData(Count, 1) = Temp2
- Temp1 = Second1
- Temp2 = Second2
- x = 10
Part 1(e)(iii) — solution
- Calling sorting procedure with correct parameters
- Outputting the array before and after procedure call
Python
ReadHighScores()
OutputHighScore()
Username = input("Enter your Username")
Score = -1
while Score < 0 or Score > 100000:
Score = int(input("Enter score"))
Arrange(Username, Score)
OutputHighScore()
2022 Page 15 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- Calling sorting procedure with correct parameters
- Outputting the array before and after procedure call
Part 1(e)(iii) — solution
- Username = Console.ReadLine()
- Score = -1
- Score = Console.ReadLine()
Visual Basic (VB.NET)
OutputHighScore()
Username = Console.ReadLine()
Score = -1
While(score < 0 or Score > 100000)
Score = Console.ReadLine()
End While
Arrange(Username, Score)
OutputHighScore()
Mark points
- Username = Console.ReadLine()
- Score = -1
- Score = Console.ReadLine()
Part 1(e)(iv) — solution
Mark points
- Include the ideas shown in the solution above.
Part 1(f) — solution
- procedure header and end (where appropriate) and opening the file NewHighScore.txt to write
- Closing the file
- Looping through all 10 array values …
- … writing the username, then the score
- Exception handling and appropriate output
Python
def WriteTopTen():
Filename = " NewHighScore.txt"
Filename = open(Filename, 'w')
for x in range(0, 10):
Filename.write(str(FileData[x][0]) + '\n')
Filename.write(str(FileData[x][1]) + '\n')
Filename.close
2022 Page 17 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- procedure header and end (where appropriate) and opening the file NewHighScore.txt to write
- Closing the file
- Looping through all 10 array values …
- … writing the username, then the score
- Exception handling and appropriate output
Part 1(f) — solution
- Dim Filename As String = " NewHighScore.txt"
- For x = 0 To 9
Visual Basic (VB.NET)
Sub WriteTopTen()
Dim Filename As String = " NewHighScore.txt"
Dim NewFile As New System.IO.StreamWriter(Filename)
For x = 0 To 9
NewFile.WriteLine(FileData(x, 0))
NewFile.WriteLine(FileData(x, 1))
Next
NewFile.Close()
End Sub
2022 Page 18 of 34
9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2022
Mark points
- Dim Filename As String = " NewHighScore.txt"
- For x = 0 To 9
Part 1 — solution
Mark points
- Include the ideas shown in the solution above.
Part 1 — solution
- IF NumberItems = 10 THEN
- IF TailPointer >= 9 THEN
Mark points
- IF NumberItems = 10 THEN
- IF TailPointer >= 9 THEN

