Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 37
Medium

Develop an algorithm, using either pseudo-code or a flowchart, that:

  • initialises a variable called validCode to False
  • sets the variable validCode to True if the string contained in the variable pCode is exactly 2 characters in length, begins with an uppercase P, and has a single numeric digit as its second character

Examples:

  • If the value of pCode is "P4" or "P0", then validCode should be True
  • If the value of pCode is "p4", "Px", or "P42", then validCode should be False

You may wish to use the following in your answer:

  • The subroutine isDigit(ch) which returns True if the character ch is a digit (e.g., "0" to "9") and False otherwise.
  • The function length(string) which returns the number of characters in a string.
[3]

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms