Past-paper question · 2023 May-June · Paper 41 · Q3(b)(iii)
Question 3(b)(iii) 2023 · May-June · Paper 41 · 5 marks
Reveal official mark-scheme answer
Official answer for Question 3
Part (b)
(iii)
Question 1
mark
Question 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 // looping 8 times
✓
Calling PushAnimal() with each line read from file (for all lines)
✓
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());
✓
}
✓
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
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2023
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
Show text version of question
Question 3
Part (b)
(iii)
Question 3
A program implements two stacks using 1D arrays. One stack stores the names of colours. One
stack stores the names of animals.
(iii)
The procedure ReadData():
- reads the animal names from the file AnimalData.txt
- uses PushAnimal() to insert each name onto the stack
- uses appropriate exception handling if the file does not exist.
Write program code for the procedure ReadData()
Save your program.
Copy and paste the program code into part 3(b)(iii) in the evidence document.
[5]
Topic relevance
Why this question appears here
72% 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_s23_qp_41.pdf
Keep practising this topic
Related searches for this question
Computer Science For First Examination In 2021 9618 topical past papers
Computer Science For First Examination In 2021 9618 topical questions with answers
AS & A Level Computer Science For First Examination In 2021 topical past papers
Computer Science For First Examination In 2021 9618 Programming topical questions
Constructs past paper questions
Computer Science For First Examination In 2021 9618 2023 May-June question
