Computer Science 9618/41 — October/November 2023
Cambridge A-Level · Practical · worked solutions for every part, with the mark scheme
Topics Programming Paradigms (Procedural and Object-oriented) · File Processing and Exception Handling · Recursion · Algorithms and Abstract Data Types
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
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.
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.
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.
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.
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.
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.
The rest of this paper
2 more questions- Q2Algorithms and Abstract Data Types · Programming Paradigms (Procedural and Object-oriented) · File Processing and Exception Handling29M
- Q3Programming Paradigms (Procedural and Object-oriented) · File Processing and Exception Handling30M