Skip to main content
A-LevelComputer ScienceProgramming9618/21 · Oct/Nov 2022 · Q710 Marks

A simple arithmetic expression is stored as a string in the format: <Value1><Operator><Value2> An operator character is one of the following: '+' '-' '*' '/' Example arithmetic expression strings: "803+1904" "34/7" (a) A procedure Calculate() will: • take an arithmetic expression string as a parameter • evaluate the expression • output the result. Assume: • the string contains only numeric digits and a single operator character • Value1 and Value2 represent integer values • Value1 and Value2 are unsigned (they will not be preceded by '+' or '-').

  1. (a)(i)Write pseudocode for the procedure Calculate().[7]
  2. (a)(ii)Calculate() is changed to a function that returns the value of the evaluated expression. Write the header for the function in pseudocode.[1]
  3. (b)A string representing an arithmetic expression could be in the correct format but be impossible to evaluate. Give an example of a correctly formatted string and explain why evaluation would be impossible. Example string Explanation[2]

Mark scheme

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

  1. [1] (a)(i) Declaration of local variables for Par1 Par2 and Par3
  2. [1] (a)(i) Loop to end of (parameter) string // until operator is found
  3. [1] (a)(i) Extract a character in a loop...
  4. [1] (a)(i) Attempt at extraction of three parts of expression using substring functions
  5. [1] (a)(i) Completely correct extraction of all three parts of expression
  6. [1] (a)(i) Convert string to Integer using STR_TO_NUM(<something sensible>)
  7. [1] (a)(i) Attempt to interpret at least two operators (Par2): + - * /
  8. [1] (a)(i) Corresponding correct calculation (all operators) and final Output of result
  9. PROCEDURE Calculate(Expression : STRING) DECLARE Val1, Val2, Index : INTEGER DECLARE Result : REAL DECLARE Par1, Par2, Par3 : STRING CONSTANT PLUS = '+' CONSTANT MINUS = '-' CONSTANT MULTIPLY = '*' CONSTANT DIVIDE = '/' FOR Index <- 1 TO LENGTH(Expression) //search for operator ThisChar <- MID(Expression, Index, 1) IF IS_NUM(ThisChar) = FALSE THEN Par1 <- LEFT(Expression, Index - 1) Par2 <- ThisChar Par3 <- RIGHT(Expression, LENGTH(Expression) - Index) // Added EXIT FOR or similar in explanation for clarity ENDIF NEXT Index Val1 <- STR_TO_NUM(Par1) Val2 <- STR_TO_NUM(Par3) CASE OF Par2 PLUS : Result <- Val1 + Val2 MINUS : Result <- Val1 - Val2 MULTIPLY : Result <- Val1 * Val2 DIVIDE : Result <- Val1 / Val2 ENDCASE OUTPUT Result ENDPROCEDURE
  10. [1] (a)(ii) FUNCTION Calculate(Expression : STRING) RETURNS REAL
  11. [1] (b) Example string: "23/0" (Any divide by zero example)
  12. [1] (b) Reason: The result is infinity / cannot be represented / is undefined // will cause the program to crash

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 2022 Paper 2 Variant 1, question 7.

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