Skip to main content
A-LevelComputer ScienceData types and structures9618/41 · May/June 2023 · Q325 Marks

A program implements two stacks using 1D arrays. One stack stores the names of colours. One stack stores the names of animals.

  1. (a)The program contains the following global arrays and variables: • 1D array Animal to store the names of up to 20 animals. • 1D array Colour to store the names of up to 10 colours. • AnimalTopPointer to point to the next free space in the array Animal, initialised to 0. • ColourTopPointer to point to the next free space in the array Colour, initialised to 0. Write program code to declare the global arrays and variables.[3]
  2. (b)(i)Study the pseudocode function PushAnimal(): FUNCTION PushAnimal(DataToPush : STRING) RETURNS BOOLEAN IF AnimalTopPointer = 20 THEN RETURN FALSE ELSE Animal[AnimalTopPointer] ← DataToPush AnimalTopPointer ← AnimalTopPointer + 1 RETURN TRUE ENDIF ENDFUNCTION Write program code for the function PushAnimal()[3]
  3. (b)(ii)Study the pseudocode function PopAnimal(): FUNCTION PopAnimal() RETURNS STRING DECLARE ReturnData : STRING IF AnimalTopPointer = 0 THEN RETURN "" ELSE ReturnData ← Animal[AnimalTopPointer - 1] AnimalTopPointer ← AnimalTopPointer - 1 RETURN ReturnData ENDIF ENDFUNCTION Write program code to declare the function PopAnimal()[3]
  4. (b)(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()[5]
  5. (b)(iv)The function PushColour() performs the same actions as PushAnimal() but inserts an item into Colour. The function PopColour() performs the same actions as PopAnimal() but removes the next item from Colour. Write program code for the functions PushColour() and PopColour()[2]
  6. (b)(v)Amend the procedure ReadData() so that it also: • reads the colours from the text file ColourData.txt • uses PushColour() to insert each colour onto the stack • uses appropriate exception handling if the file does not exist.[2]
  7. (c)The procedure OutputItem(): • pops the next item from both Animal and Colour • outputs the colour and animal on one line, for example "black horse" If there is no data in Colour: • the animal is pushed back onto Animal • "No colour" is output. If there is no data in Animal: • the colour is pushed back onto Colour • "No animal" is output. Write program code for the procedure OutputItem()[5]
  8. (d)(i)The main program: • calls the procedure ReadData() • calls OutputItem() four times. Write program code for the main program.[1]
  9. (d)(ii)Test your program. Take a screenshot of the output.[1]

Mark scheme

Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.

  1. [3] 1 mark each • (Global) Animal array (with 20 string elements) • (Global) Colour array (with 10 string elements) • (Global) AnimalTopPointer and ColourTopPointer initialised to 0
  2. [3] 1 mark each • Function header (and close where appropriate) with parameter, checking if full (AnimalTopPointer = 20) and returning false • If not full, inserting parameter value into AnimalTopPointer • ...incrementing pointer and returning true
  3. [3] 1 mark each • Procedure header (and end where appropriate) with no parameter, checking if empty (AnimalTopPointer = 0) and returning empty string • If not empty returning the top data item (AnimalTopPointer-1) • ...and decrementing AnimalTopPointer
  4. [5] 1 mark • 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
  5. [2] 1 mark each • PushColour function • PopColour function
  6. [2] 1 mark each • Opening ColourData.txt to read, reading until EOF, closing file and exception handling • Using PushColour () to store each item read from the file for all lines
  7. [5] 1 mark each to max 5 • Procedure heading (and close where appropriate) and outputting the colour and animal using PopColour() and PopAnimal() (only if both are successfully popped) • Checking if no colour and outputting "No colour" • ....pushing the removed animal back onto the stack • Checking if no animal and outputting "No animal" • ...pushing the removed colour back onto the stack
  8. [1] 1 mark for • Calling ReadData() and calling OutputItem() 4 times
  9. [1] 1 mark for output e.g. pink hamster blue elephant white eagle yellow rabbit

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Data types and structures, A-Level Computer Science (syllabus 9618). Structured question, 25 marks.
Source
A-Level Computer Science, May/June 2023 Paper 4 Variant 1, question 3.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep