Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314
Question 11
Hard

Write a subroutine in VB.Net called monitorPollution that counts the number of plastic pollution hotspots in a marine survey grid.

The marine survey grid is represented as a 4x4 2D array of strings, where hotspots are represented by the string "P".

An example of the oceanGrid array is shown in Figure 1 below:

Figure 1

0123
0ClearPClearClear
1PClearPClear
2ClearClearClearP
3PPClearClear

Environmental protection protocols require you to determine if an area is critically polluted.

The subroutine should:

  • Take the 4x4 2D array oceanGrid as a parameter
  • Count the number of "P" elements in the array
  • Output the word "Critical" if there are seven or more "P" elements in the array
  • Output the total number of "P" elements if there are fewer than seven.

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)