Skip to main content
A-LevelComputer ScienceProgramming9618/21 · May/June 2024 · Q68 Marks

Three points on a grid form a triangle with sides of length A, B and C as shown in the example: y 10 9 8 7 6 5 C B 4 3 2 A 1 X 0 1 2 3 4 5 6 7 8 9 10 A triangle is said to be right-angled if the following test is true (where A is the length of the longest side): A2 = B2 + C2 A2 means A multiplied by A, for example 32 means 3 × 3 which evaluates to 9 You can calculate A2, B2 and C2 by using the coordinates of the endpoints of each line. For example, B2 is calculated as follows: y 10 9 8 7 P2 6 (Х2, У2) 5 B 4 3 P1 2 (Х₁, У₁) 1 X 0 1 2 3 4 5 6 7 8 9 10 The endpoints, P1 and P2, have the coordinates (3, 2) and (6, 6). The value B2 is given by the formula: B2 = (x₁ − x₂)2 + (y₁ – y₂)2 In this example: B2 = (3 – 6)2 + (2 – 6)2 B2 = (−3)2 + (−4)2 B2 = 9 + 16 B2 = 25

  1. (a)A function IsRA () will: • take three sets of integers as parameters representing the coordinates of the three endpoints that form a triangle • return TRUE if the endpoints form a right-angled triangle, otherwise return FALSE. In pseudocode, the operator '^' represents an exponent, which is the number of times a value is multiplied by itself. For example, the expression Value2 may be written in pseudocode as Value ^ 2 Complete the pseudocode for the function IsRA(). FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN ENDFUNCTION[6]
  2. (b)The test used to check if a triangle is right-angled can be written in two ways: A2 = B2 + C2 or A = √(B2 + C2) The symbol √ represents the square root operation. For example, √81 = 9 A new function SQRT() is written to perform the square root operation. The function takes an integer number as a parameter and returns a positive real value representing the square root of the number. During testing it is found that the SQRT() function returns a value that is only accurate to 4 decimal places. For example, SQRT(25) returns 5.0000125 rather than the correct value of 5.0 The function IsRA() from part (a) is modified to use the new SQRT() function to test if a triangle is right-angled. Describe a problem that might occur when using the modified IsRA() function and suggest a solution that still allows the SQRT() function to be used. Problem Solution[2]

This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.

Mark scheme

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

  1. [6] FUNCTION IsRA(x1, y1, x2, y2, x3, y3 : INTEGER) RETURNS BOOLEAN
  2. DECLARE Len1, Len2, Len3 : INTEGER
  3. Len1 ← (x1 - x2) ^ 2 + (y1 - y2) ^ 2
  4. Len2 ← (x1 - x3) ^ 2 + (y1 - y3) ^ 2
  5. Len3 ← (x2 - x3) ^ 2 + (y2 - y3) ^ 2
  6. IF (Len1 = Len2 + Len3) OR
  7. (Len2 = Len1 + Len3) OR
  8. (Len3 = Len1 + Len2) THEN
  9. RETURN TRUE
  10. ELSE
  11. RETURN FALSE
  12. ENDIF
  13. ENDFUNCTION
  14. Mark as follows:
  15. 1 Calculate the square of the length of at least one side
  16. 2 Calculation of all three lengths squared correctly
  17. 3 One correct comparison of square of three lengths
  18. 4 All three comparisons...
  19. 5 combined using logical operators / nested IF // completely correct selection
  20. 6 Return result correctly in both cases
  21. [2] 1 mark for statement of problem:
  22. Problem:
  23. • The function will return an incorrect value // the test will fail
  24. 1 mark for solution:
  25. Solution:
  26. • Round the calculated values (to a known number of decimal places)
  27. • Define a threshold below which any difference can be ignored

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, 8 marks.
Source
A-Level Computer Science, May/June 2024 Paper 2 Variant 1, question 6.

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