A program stores lower-case letters in two stacks. One stack stores vowels (a, e, i, o, u) and one stack stores consonants (letters that are not vowels). Each stack is implemented as a 1D array.
- (a)(i)Write program code to declare two 1D global arrays: StackVowel and StackConsonant. Each array needs to store up to 100 letters. The index of the first element in each array is 0. If you are writing in Python, include declarations using comments. Save your program as Question1_N23. Copy and paste the program code into part 1(a)(i) in the evidence document.[2]
- (a)(ii)The global variable VowelTop is a pointer that stores the index of the next free space in StackVowel. The global variable ConsonantTop is a pointer that stores the index of the next free space in StackConsonant. VowelTop and ConsonantTop are both initialised to 0. Write program code to declare and initialise the two variables. If you are writing in Python, include declarations using comments. Save your program. Copy and paste the program code into part 1(a)(ii) in the evidence document.[1]
- (b)(i)The procedure PushData() takes one letter as a parameter. If the parameter is a vowel, it is pushed onto StackVowel and the relevant pointer updated. If the stack is full, a suitable message is output. If the parameter is a consonant, it is pushed onto StackConsonant and the relevant pointer updated. If the stack is full, a suitable message is output. You do not need to validate that the parameter is a letter. Write program code for PushData(). Save your program. Copy and paste the program code into part 1(b)(i) in the evidence document.[6]
- (b)(ii)The file StackData.txt stores 100 lower-case letters. The procedure ReadData() reads each letter from the file and uses PushData() to push each letter onto its appropriate stack. Use appropriate exception handling if the file does not exist. Write program code for ReadData(). Save your program. Copy and paste the program code into part 1(b)(ii) in the evidence document.[6]
- (c)The function PopVowel() removes and returns the data at the top of StackVowel and updates the relevant pointer(s). The function PopConsonant() removes and returns the data from the top of StackConsonant and updates the relevant pointer(s). If either stack is empty, the string "No data" must be returned. Write program code to declare PopVowel() and PopConsonant(). Save your program. Copy and paste the program code into part 1(c) in the evidence document.[5]
- (d)(i)The program first needs to call ReadData() and then: 1. prompt the user to input their choice of vowel or consonant 2. take, as input, the user's choice 3. depending on the user's choice, call PopVowel() or PopConsonant() and store the return value. The three steps are repeated until 5 letters have been successfully returned and stored. If either stack is empty at any stage, an appropriate message must be output. Once 5 letters have been successfully returned and stored, they are output on one line, for example: abyti Write program code for the main program. Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document.[6]
- (d)(ii)Test your program with the following inputs: vowel consonant consonant vowel vowel Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 1(d)(ii) in the evidence document.[1]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.
- [2] One mark each • Two arrays with correct identifiers of type string/character • Each has 100 elements
- [1] One mark for • Declaring both variables as type integer global and initialised to 0
- [6] One mark each • Procedure PushData() heading (and end where appropriate) taking one parameter • Checking if parameter is a (lowercase) vowel ... • ... checking if StackVowel is full and outputting suitable message • ... otherwise inserting parameter in next position • ... incrementing VowelTop • Repeated for Consonant
- [6] One mark each • Procedure header ReadData() with no parameter • Opening StackData.txt to read and closing file • Looping until EOF // Looping 100 times • Read each item from the file • Calling PushData() with each value as parameter • Appropriate exception handling with suitable output
- [5] One mark each • One function header with no parameter • Checking if stack is empty and returning "No data" • ...otherwise, decrementing correct pointer • Returning value at top of stack • 2nd function fully correct
- [6] One mark each to max 6 • Calling ReadData() • Looping until 5 letters successfully accessed • Prompt and read in input of choice ... • ... if vowel is input calling PopVowel() and if consonant calling PopConsonant() ... • ... storing return values • Outputting appropriate message if no vowels and if no consonants (stacks full) within loop • Outputting the five returned letters on one line
- [1] One mark showing input in order vowel, cons, cons, vowel, vowel. Output is then utxoe
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 →