A procedure Select () will: 1. take two integer values as parameters representing start and end values where both values are greater than 9 and the end value is greater than the start value 2. output each integer value between the start and the end value (not including the start and end values), where the sum of the last two digits is 6, for example, 142.
- (a)Write pseudocode for procedure Select(). Parameter validation is not required.[7]
- (b)The check performed by procedure Select() on the last two digits is needed at several places in the program and will be implemented using a new function. The new function CheckNum() will: • allow the required sum to be specified (not just 6) • check one number • return an appropriate value. Describe the function interface and two advantages of this modular approach. Interface Advantage 1 Advantage 2[4]
Mark scheme
Marking points from the official mark scheme (May/June 2023). The mark or mark type is shown in brackets.
- [7] PROCEDURE Select(Start, End : INTEGER)
- [7] DECLARE ThisNum, Total: INTEGER
- [7] DECLARE ThisString : STRING
- [7] DECLARE Char1, Char2 : CHAR
- [7] FOR ThisNum ← Start+1 TO End-1
- [7] ThisString ← NUM_TO_STR(ThisNum)
- [7] Char1 ← RIGHT(ThisString, 1)
- [7] Char2 ← LEFT(RIGHT(ThisString, 2), 1)
- [7] Total ← STR_TO_NUM(Char1) + STR_TO_NUM(Char2)
- [7] IF Total = 6 THEN
- [7] OUTPUT ThisString
- [7] ENDIF
- [7] NEXT ThisNum
- [7] ENDPROCEDURE
- [7] MP1 Procedure heading and ending
- [7] MP2 (Count-controlled) Loop
- [7] MP3 ... with correct range from Start+1 to End-1
- [7] MP4 Convert ThisNum (loop counter) to a string
- [7] MP5 Extract the last two/first/second 'character digit(s)' required in a loop
- [7] MP6 Extract the second individual 'character digit' required in a loop
- [7] MP7 Calculate the sum of the last two digits
- [7] MP8 If sum = 6 then OUTPUT the number (either string or integer) in a loop
- [4] Max 4 marks
- [4] MP1 The function will take two integer parameters - the number and the (required) total
- [4] MP2 ... and return a Boolean
- [4] OR: CheckNum(Number,Total : INTEGER) RETURNS BOOLEAN
- [4] Two marks for the advantages:
- [4] MP3 CheckNum() can be called repeatedly as and when required
- [4] MP4 CheckNum() is designed and tested once (then used repeatedly)
- [4] MP5 Any subsequent change to CheckNum() needs to be made once only // is easier to maintain/modify
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 →