Past-paper question · 2025 May-June · Paper 43 · Q1(d)

Question 1(d) 2025 · May-June · Paper 43 · 6 marks

Original past-paper question for 1(D)
Original past-paper question for 1(D)
Original past-paper question for 1(D)
Reveal official mark-scheme answer Official mark-scheme answer for 1(D)Official mark-scheme answer for 1(D)Official mark-scheme answer for 1(D)

Official answer for Question 1

Part (d)

Question 1

mark each

Question 6

  • CreateQueue() header (and end) and opening the file to read and closing file in appropriate place
  • Looping until end of file
  • Reading in each/all lines (and converting to integer and removing new line)
  • … calling Enqueue() once with each value …
  • … checking return value and outputting "Queue full" if full (can output once or many times)
  • Exception try, catch with appropriate output. All file access within try
✓
9618/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example program code:
✓
Python
✓
def CreateQueue():
✓
try:
✓
File = open("QueueData.txt")
✓
for Line in File:
✓
ReturnValue = Enqueue(int(Line))
✓
if ReturnValue == False:
✓
print("Queue full")
✓
break;
✓
File.close()
✓
except:
✓
print("Cannot open or read file")
✓
VB.NET
✓
Sub CreateQueue()
✓
Dim ReturnValue As Boolean
✓
Dim ReadData As Integer
✓
Try
✓
Dim FileReader As New System.IO.StreamReader("QueueData.txt")
✓
While Not FileReader.EndOfStream
✓
ReadData = FileReader.ReadLine()
✓
ReturnValue = Enqueue(ReadData)
✓
If ReturnValue = False Then
✓
Console.WriteLine("Queue full")
✓
End If
✓
End While
✓
FileReader.Close()
✓
Catch ex As Exception
✓
Console.WriteLine("Cannot open or read file")
✓
End Try
✓
End Sub
✓
9618/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Java
✓
public static void CreateQueue(){
✓
Boolean ReturnValue;
✓
Integer ReadData;
✓
try{
✓
FileReader f = new FileReader("QueueData.txt");
✓
try{
✓
BufferedReader Reader = new BufferedReader(f);
✓
String Line = Reader.readLine();
✓
Line = Line.replace("\n","");
✓
while (Line != null){
✓
Line = Line.replace("\n","");
✓
ReturnValue = Enqueue(Integer.parseInt(Line));
✓
if (ReturnValue == false){
✓
System.out.println("Queue full");
✓
}
✓
Line = Reader.readLine();
✓
}
✓
Reader.close();
✓
}catch(IOException ex){
✓
}
✓
}catch(FileNotFoundException e){ System.out.println("Cannot open or read file");}
✓
}
✓
9618/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s25_ms_43.pdf →

Show text version of question

Question 1

Part (d)

Question 1

A program reads data from a text file and stores it in a queue. The linear queue Queue is stored as

a 1D array of up to 50 elements. The queue has the following pointers:

  • HeadPointer – this stores the index of the first element in the queue, initialised to –1
  • TailPointer – this stores the index of the last element in the queue, initialised to –1

Part (d)

The text file QueueData.txt stores positive integers. Each integer is on a new line in the

file.

The procedure CreateQueue():

  • opens the file QueueData.txt
  • reads in each line from the text file and uses Enqueue() to insert each line into the
  • queue

  • outputs "Queue full" if any item cannot be inserted into the queue
  • uses exception handling when opening and reading from the text file.

The procedure needs to work for a file that contains an unknown number of lines.

Write program code for CreateQueue()

Save your program.

Copy and paste the program code into part 1(d) in the evidence document.

[6]
Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Constructs

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9618_s25_qp_43.pdf

Keep practising this topic