The following pseudocode algorithm attempts to check whether a string is a valid email address. FUNCTION IsValid(InString : STRING) RETURNS BOOLEAN DECLARE Index, Dots, Ats, Others : INTEGER DECLARE NextChar : CHAR DECLARE Valid : BOOLEAN Index <- 1 Dots <- 0 Ats <- 0 Others <- 0 Valid <- TRUE REPEAT NextChar <- MID(InString, Index, 1) CASE OF NextChar '.' : Dots <- Dots + 1 '@' : Ats <- Ats + 1 IF Ats > 1 THEN Valid <- FALSE ENDIF OTHERWISE : Others <- Others + 1 ENDCASE IF Dots > 1 AND Ats = 0 THEN Valid <- FALSE ELSE Index <- Index + 1 ENDIF UNTIL Index > LENGTH(InString) OR Valid = FALSE IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN Valid <- FALSE ENDIF RETURN Valid ENDFUNCTION
- (a)Part of the validation is implemented by the line: IF NOT (Dots >= 1 AND Ats = 1 AND Others > 8) THEN State the values that would result in the condition evaluating to TRUE.[1]
- (b)(i)Complete the trace table by dry running the function when it is called as follows: Result <- IsValid("Liz.123@big@net") Index NextChar Dots Ats Others Valid[5]
- (b)(ii)State the value returned when IsValid() is called using the expression shown in part (b)(i).[1]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2022). The mark or mark type is shown in brackets.
- [1] (a) Condition evaluates to TRUE if bracket contents evaluate to FALSE:
- [1] (a) Bracket contents evaluate to FALSE if: Dots: zero / less than one or Ats: not equal to one or Others: less than nine
- [1] (b)(i) Row for Index 1-3 NextChar 'L','i','z', Others 1,2,3 (with Dots 0, Ats 0, Valid TRUE implied)
- [1] (b)(i) Row for Index 4 NextChar '.', Dots 1 (with Others 3, Ats 0, Valid TRUE implied)
- [1] (b)(i) Row for Index 5-7 NextChar '1','2','3', Others 4,5,6 (with Dots 1, Ats 0, Valid TRUE implied)
- [1] (b)(i) Row for Index 8 NextChar '@', Ats 1 (with Dots 1, Others 6, Valid TRUE implied)
- [1] (b)(i) Row for Index 9-11 NextChar 'b','i','g', Others 7,8,9; Row for Index 12 NextChar '@', Ats 2, Valid FALSE (with Dots 1, Others 9 implied)
- [1] (b)(ii) FALSE
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 →