Question 1(d) 2025 · May-June · Paper 42 · 6 marks
Reveal official mark-scheme answer

Official answer for Question 1
Part (d)
Question 1
mark each
Question 6
- Procedure header (and end where appropriate) taking one (string) parameter
- Opening the file with the filename parameter and closing the file in an appropriate place
- Looping through to end of file and reading in each line ...
- … calling Push() once with each read in value …
- … if any return value from Push() is integer –1 outputting "Stack full"
- Exception handling for opening and reading from file with appropriate catch and output
Show text version of question
Question 1
Part (d)
Question 1
A program reads data from a text file and stores it in a stack. The stack Stack is stored as a 1D
array of up to 20 elements. The pointer TopOfStack stores the index of the last element stored in the stack.
Part (d)
The text file StackData.txt stores numbers and mathematical operators. Each number
and operator are on a new line in the text file.
The mathematical operators used in this program are:
mathematical meaning operator + addition
- subtraction
/ division * multiplication ^ power of
The procedure ReadData():
- takes a string filename as a parameter
- opens the file and reads in each line of data
- uses the Push() function to insert each line of data onto the stack
- outputs "Stack full" if any data cannot be stored on the stack because the stack is
- uses exception handling when opening and reading from the text file.
full
The procedure needs to work for a file that contains an unknown number of lines.
Write program code for ReadData()
Save your program.
Copy and paste the program code into part 1(d) in the evidence document.
Question 4
Why this question appears here
82% assigned-topic match · Programming › Structured programming
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_42.pdf
