May/June 2026 Paper 41

2026 · 3 questions · 23 parts · 75 marks

0/75 marks
0Correct0Partial0Wrong23Unattempted
Filters0 active
Context for question 2
A program stores data about toys that are made from bricks. The toys are stored in a record structure with four fields:
ToyNamethe string name of the toy
NumberBricksthe integer number of bricks in the toy
Difficultythe string difficulty level of the toy (easy, medium or expert)
Categorythe string category of the toy (for example town, display, play)
2(a)Records User Defined Data TypesEasy2 marks
Write program code to declare a record structure with the identifier ToyRecord and the four fields.

Answer

0 words
Context for 2(b)
The text file Toys.txt stores data about 16 toys. Each toy is on a new line in the file. The data is stored in the order: toy name, number of bricks, difficulty, category. Each value is separated by a comma.
For example, the first line in the file is:
text
Fire Station,3981,Expert,Town
The name of the toy is Fire Station. The toy has 3981 bricks. The difficulty level is Expert. The category is Town.
2(b)(i)File Handling ExceptionsHard8 marks
The function ReadData():
  • takes an array of type ToyRecord as a parameter
  • opens the file Toys.txt and reads in the data
  • creates a new record of type ToyRecord for each toy read from the file
  • stores each record in the parameter array
  • returns the populated array
The function uses exception handling when opening and reading from the file.
Write program code for ReadData().

Answer

0 words
2(b)(ii)ArraysMedium3 marks
The procedure OutputToys() takes an array of type ToyRecord as a parameter and outputs the data for each toy in the array.
Write program code for OutputToys().

Answer

0 words
2(b)(iii)Subroutines Scope Modular ProgrammingMedium3 marks
Write program code for the main program to:
  • declare an array of type ToyRecord with space for 16 elements
  • call the function ReadData() with the empty array and store the returned array
  • call OutputToys() with the returned array

Answer

0 words
2(b)(iv)File Handling ExceptionsEasy1 mark
Test your program using the supplied Toys.txt file.
Describe what your program outputs.

Answer

0 words
Context for 2(c)
The program needs to allow a user to enter the difficulty level of a toy and then write all toys that match that difficulty level to an external text file.
2(c)(i)Searching AlgorithmsMedium5 marks
The function SearchToys():
  • takes an array of type ToyRecord as a parameter
  • prompts the user to enter the difficulty level
  • takes the difficulty level as input until it is valid
  • creates a new array containing the ToyRecord objects that match the difficulty level input
  • returns the populated array
Write program code for SearchToys().

Answer

0 words
2(c)(ii)File Handling ExceptionsMedium3 marks
The procedure WriteToys():
  • takes an array of type ToyRecord as a parameter
  • creates and opens the file SelectedToys.txt to write
  • writes each record from ToyRecord to SelectedToys.txt with each field separated by a comma and each record on a new line
For example:
text
<ToyName>,<NumberBricks>,<Difficulty>,<Category>
Write program code for WriteToys().

Answer

0 words
2(c)(iii)Subroutines Scope Modular ProgrammingEasy2 marks
Write program code to extend the main program to:
  • call SearchToys() with the populated array and store the return array
  • call WriteToys() with the returned array

Answer

0 words
2(c)(iv)File Handling ExceptionsEasy1 mark
Test your program. Enter the appropriate input for a medium difficulty level when prompted.
Describe the exact contents written to SelectedToys.txt (the filename and every line written to it).

Answer

0 words