Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314
Question 12
Hard

Write a subroutine in VB.Net called checkHazards that counts the number of hazardous material containers in a shipping yard grid.

The shipping yard is represented as a 4x4 2D array of strings, where hazardous containers are represented by the string "H".

An example of the yard array is shown in Table 1 below:

Table 1

0123
0CargoHCargoEmpty
1EmptyCargoHCargo
2CargoCargoEmptyEmpty
3HCargoCargoH

Safety protocols require you to identify if the yard has a dangerous accumulation of hazards.

The subroutine should:

  • Take the 2D array yard as a parameter
  • Count the number of "H" elements in the array
  • Output the word "Danger" if there are three or more "H" elements in the array
  • Output the total number of "H" elements if there are fewer than three.

You must write your own counting routine utilizing nested loops and not use any built-in search or counting functions that might be available in VB.Net. You can assume the nested loops will iterate over a fixed 4x4 grid.

You should use meaningful variable names and correct VB.Net syntax in your answer.

[8]

Structured programming and subroutines (procedures and functions) Questions

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