Skip to main content
A-LevelComputer ScienceProgramming9618/21 · Oct/Nov 2024 · Q410 Marks

A program includes the following assignment statement: Result ← STR_TO_NUM(x) / STR_TO_NUM(y) When the program evaluates the expression in the statement, it performs a calculation. Variable Result is of type real and variables x and y are of type string. Two checks are required before the calculation is performed: 1. The two strings represent valid numeric values. 2. The numeric value of string y is not zero.

  1. (a)Identify the type of error that could occur if these checks are not carried out and state a cause of this error. Type Cause[2]
  2. (b)The designer considers implementing the checks and calculation as a module (a procedure or a function). One reason for this is that the same checks and calculations are performed at several places in the program. Give another reason why this is a suitable approach and state what is avoided by this approach. Reason Avoided[2]
  3. (c)The module to perform the checks and calculation will be implemented as a function. The function will need to return both a real and a Boolean value. To achieve this a record type is defined in pseudocode as follows: TYPE Result DECLARE Done : BOOLEAN DECLARE Value : REAL ENDTYPE The function Evaluate() will: • take two parameters of type string representing the two numeric values • return a variable of type Result with the Done field set to FALSE if either of the following applies: o at least one of the strings does not represent a valid numeric value o the numeric value of the string representing value y is zero • otherwise return a variable of type Result with the Done field set to TRUE and the Value field assigned the result of the formula (based on the numeric value of the two parameters). Write pseudocode for the function Evaluate().[6]

Mark scheme

Marking points from the official mark scheme (Oct/Nov 2024). The mark or mark type is shown in brackets.

  1. [1] (a) Type: Run-time error
  2. [1] (a) Cause: A divide by zero operation is attempted // Attempt to convert a non-numeric string to a number
  3. [1] (b) Reason: This part of the algorithm performs a specific task // if the check or calculation is changed it is changed only once
  4. [1] (b) Reason: A (similar) subroutine is already available // Library routine is already available
  5. [1] (b) Reason: The program is simplified / easier to understand / easier to design / code / test / debug / maintain
  6. [1] (b) Avoided: Unnecessary code duplication
  7. [1] (b) Avoided: Errors caused by differences where several copies of the check and calculation exist
  8. [1] (c) Function heading, parameters, ending
  9. [1] (c) Correct return type of Result
  10. [1] (c) Local declaration of type Result
  11. [1] (c) Attempt at using IS_NUM() to check both parameters/strings
  12. [1] (c) Attempt at using of STR_TO_NUM() to convert both parameters/strings
  13. [1] (c) Check if the divisor, is non-zero
  14. [1] (c) and if so correct calculation and assignment to Value field
  15. [1] (c) Return variable of type Result having assigned both fields
  16. FUNCTION Evaluate(NumStr1, NumStr2 : STRING) RETURNS Result
  17. DECLARE RetVal : Result
  18. DECLARE Num1, Num2 : REAL
  19. RetVal.Done ← FALSE
  20. IF IS_NUM(NumStr1) = TRUE AND IS_NUM(NumStr2) = TRUE THEN
  21. Num1 ← STR_TO_NUM(NumStr1)
  22. Num2 ← STR_TO_NUM(NumStr2)
  23. IF Num2 <> 0 THEN
  24. RetVal.Value ← (Num1 / Num2)
  25. RetVal.Done ← TRUE
  26. ENDIF
  27. ENDIF
  28. RETURN RetVal
  29. ENDFUNCTION

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 →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 10 marks.
Source
A-Level Computer Science, Oct/Nov 2024 Paper 2 Variant 1, question 4.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep