Robust and secure programming

EasyMediumHard
12
Question 2
Hard

A logistics developer is writing a container location system for a shipping terminal. The terminal layout utilizes a 4 x 4 grid consisting of sixteen storage zones.

In the control application, a storage zone is referenced by a column letter followed by a row number. For example, zone Q7 in Figure 1 contains a shipping container marked with X.

Figure 2 shows a segment of a C# program designed to retrieve and initially filter the zone reference entered by an operator.

The zone reference is valid if and only if:

  • there are exactly two characters
  • the first character is P, Q, R, or S
  • the second character is 5, 6, 7, or 8.

Figure 1

Logistics Grid

Figure 2

bool valid = false;
while (valid == false) {
    string zone = "";
    while (zone.Length != 2) {
        Console.Write("Enter container zone (e.g. Q7): ");
        zone = Console.ReadLine();
        zone = zone.ToUpper();
    }
}

Extend the program from Figure 2 so it performs the remaining validation checks necessary to guarantee a valid zone reference is entered.

Your extended program must:

  • use the variable valid
  • repeat the steps until a valid zone reference is entered:
    • prompt the operator to enter a zone reference
    • output an appropriate error message if the entered zone reference is not valid.

You should use meaningful variable name(s) and C# syntax in your answer.

[6]

Robust and secure programming Questions

  1. GCSE
  2. /Computer Science
  3. /Robust and secure programming