Skip to content

Course home

Structured programming and subroutines (procedures and functions)

Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
Question 30

In a data encryption system designed for transmitting telemetry readings, each digit character is obfuscated by replacing it with its '9s complement' (for example, the character '3' is replaced by '6', and the character '0' is replaced by '9').

Write a subroutine COMPLEMENT_DIGIT, using either pseudo-code or a flowchart, that takes a single digit character as a parameter and returns the corresponding 9s complement character.

For example, if the subroutine COMPLEMENT_DIGIT is passed the character '2' as a parameter, the subroutine should return the character '7'.

You should make use of the built-in subroutines INT_TO_CHAR and CHAR_TO_INT in your answer:

  • CHAR_TO_INT(character) returns the integer ASCII/Unicode code for a character (e.g., CHAR_TO_INT('0') returns 48, CHAR_TO_INT('9') returns 57).
  • INT_TO_CHAR(integer) returns the character corresponding to that ASCII/Unicode code (e.g., INT_TO_CHAR(53) returns '5').

You can assume that the parameter passed to the subroutine will always be a single digit character between '0' and '9'.

[5]
Markscheme

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)

131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.

Question bank