May/June 2026 Paper 42

2026 · 3 questions · 24 parts · 75 marks

0/75 marks
0Correct0Partial0Wrong24Unattempted
Filters0 active
Context for question 2
A program stores data about avatars using Object-Oriented Programming (OOP). An avatar is a character that a user can control in a game.
The class Avatar stores the data about avatars.
Avatar
TheName : Stringstores the name of the avatar
Glasses : Booleanstores TRUE if the avatar wears glasses; stores FALSE if the avatar does not wear glasses
Hair : Stringstores the colour of the avatar's hair
Age : Integerstores the age of the avatar
Constructor()initialises all attributes to its parameter values
GetName()returns the name of the avatar
GetAge()returns the age of the avatar
MeetCriteria()takes the glasses choice and hair choice as parameters and returns whether the avatar matches the choices
2(a)(i)Classes ObjectsMedium4 marks
Write program code to declare the class Avatar and its constructor. All attributes must be private. Do not declare the other methods.
Use your programming language's appropriate constructor. If you are writing in Python, include the attribute declarations as comments.

Answer

0 words
2(a)(ii)Classes ObjectsMedium3 marks
The get methods GetName() and GetAge() each return the relevant attribute.
Write program code for GetName() and GetAge().

Answer

0 words
2(a)(iii)Classes ObjectsEasy2 marks
The method MeetCriteria() takes two parameters:
  • a Boolean value to identify whether the avatar wears glasses
  • a string value to identify the hair colour.
The method checks whether this avatar's attributes match both of the parameters. Boolean TRUE is returned when both attributes match the parameters, otherwise Boolean FALSE is returned.
Write program code for MeetCriteria().

Answer

0 words
Context for 2(b)
The text file AvatarFile.txt stores data for 30 avatars. Each avatar is on a new line in the file. The data is stored in the order: name, glasses, hair colour, age. Each value is separated by a space.
For example, the first line in the file is:
text
Kit True blonde 21
The name of the avatar is Kit, the avatar wears glasses, the avatar has blonde hair, and the avatar is 21 years old.
2(b)(i)File Handling ExceptionsHard7 marks
The procedure LoadAvatars() reads the data from the text file into the program. The procedure creates a new object for each avatar in the file and stores the avatar objects in a global array with the identifier AvailableAvatars.
The procedure uses exception handling when opening and reading from the file.
Write program code for LoadAvatars().

Answer

0 words
2(b)(ii)Subroutines Scope Modular ProgrammingEasy1 mark
Write program code for the main program to call LoadAvatars().

Answer

0 words
2(c)(i)Data Validation VerificationHard6 marks
The procedure EnterChoices() prompts the user to enter whether they want an avatar that wears glasses and the hair colour they want.
The procedure takes these two values as input until they are valid:
  • wearing glasses can only be yes or no
  • the hair colour can be black, blonde, brown, pink, red or green.
The procedure calls the method MeetCriteria() for each avatar in AvailableAvatars, and stores the avatars that match the criteria in a global array.
Write program code for EnterChoices().

Answer

0 words
2(c)(ii)Classes ObjectsMedium5 marks
Write program code to extend the main program to:
  • call EnterChoices()
  • output the quantity of avatars that match the criteria
  • output the name and age of each avatar that matches the criteria.
All outputs must include an appropriate message.

Answer

0 words
2(d)(i)Data Validation VerificationEasy1 mark
Run your program, entering: yes for the glasses choice; blue, then black, for the hair colour (blue is not one of the six valid colours, so your program should reject it and prompt again).
Describe exactly what your program outputs, in the order it is produced.

Answer

0 words
2(d)(ii)Classes ObjectsEasy1 mark
Run your program, entering: no for the glasses choice; green for the hair colour.
Describe exactly what your program outputs, in the order it is produced.

Answer

0 words