A program implements two stacks using 1D arrays. One stack stores the names of colours. One stack stores the names of animals. Study the pseudocode function PushAnimal (): Write program code for the function PushAnimal () (ii) Study the pseudocode function PopAnimal (): FUNCTION PopAnimal() RETURNS STRING DECLARE ReturnData : STRING IF AnimalTopPointer $$\(=0\)$$ THEN RETURN "" ELSE ReturnData $$\(\leftarrow\)$$ Animal[AnimalTopPointer - 1] AnimalTopPointer $$\(\leftarrow\)$$ AnimalTopPointer - 1 RETURN ReturnData ENDIF ENDFUNCTION Write program code to declare the function PopAnimal () (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 () (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() (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.

Computer Science
IGCSE&ALevel
CAIE
Exam No:9618_s23_qp_43 Year:2023 Question No:3(b)

Answer:



















Knowledge points:

20.2 File Processing and Exception Handling

Solution:

Download APP for more features
1. Tons of answers.
2. Smarter Al tools enhance your learning journey.
IOS
Download
Android
Download
Google Play
Download