This iterative pseudocode algorithm for the function IterativeVowels() takes a string as a parameter and counts the number of lower-case vowels in this string. The vowels are the letters a, e, i, o and u. FUNCTION IterativeVowels(Value : STRING) RETURNS INTEGER DECLARE Total : INTEGER DECLARE LengthString : INTEGER DECLARE FirstCharacter : CHAR Total ← 0 LengthString ← LENGTH(Value) FOR X ← 0 TO LengthString – 1 FirstCharacter ← MID(Value, 0, 1) IF FirstCharacter = 'a' OR FirstCharacter = 'e' OR FirstCharacter = 'i' OR FirstCharacter = 'o' OR FirstCharacter = 'u' THEN Total ← Total + 1 ENDIF Value ← MID(Value, 1, LENGTH(Value)–1) NEXT X RETURN Total ENDFUNCTION The pseudocode function MID(X, Y, Z) returns Z number of characters from string X, starting at the character in position Y. The first character in a string is in position 0, for example: MID("computer", 0, 3) returns "com" The pseudocode function LENGTH(X) returns the number of characters in the string X, for example: LENGTH("computer") returns 8
- (a)(i)Write program code for the function IterativeVowels(). Save your program as Question1_N23. Copy and paste the program code into part 1(a)(i) in the evidence document.[5]
- (a)(ii)Write program code to call the function IterativeVowels() with the parameter "house" from the main program. Output the return value. Save your program. Copy and paste the program code into part 1(a)(ii) in the evidence document.[2]
- (a)(iii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 1(a)(iii) in the evidence document.[1]
- (b)(i)Rewrite the function IterativeVowels() as a recursive function with the identifier RecursiveVowels(). Save your program. Copy and paste the program code into part 1(b)(i) in the evidence document.[6]
- (b)(ii)Write program code to call the function RecursiveVowels() with the parameter "imagine" from the main program. Output the return value. Save your program. Copy and paste the program code into part 1(b)(ii) in the evidence document.[1]
- (b)(iii)Test your program. Take a screenshot of the output. Save your program. Copy and paste the screenshot into part 1(b)(iii) 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.
- [5] One mark each to max 5
- • Function header (and end where appropriate) taking one string parameter
- • Calculating length of parameter string
- • Looping correct number of times
- • Checking the first character against all vowels
- • Accessing the remainder of the string
- Remainder of function correct with nothing extra i.e. totalling, must match structure of given algorithm
- [2] One mark each
- • Calling the function with "house"
- • Outputting the return value
- [1] One mark for screenshot outputting 3
- [6] One mark each
- • Recursive call
- • Function header (and end where appropriate) taking string parameter (returning integer where given)
- • Base case checking (length is 0) and returning 0
- • Extracting first character and checking if a vowel
- • ... if it is a vowel, returning 1 + recursive call with 1 less character
- • ... if not a vowel, return recursive call with 1 less character
- [1] One mark for calling recursive function with "imagine" and outputting return value
- [1] One mark for screenshot showing 4
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 →