Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314
Question 9
Hard

Write a subroutine in VB.Net called checkWeeds that counts the number of weeds in a garden grid.

The garden is represented as a 3x3 2D array of strings, where weeds are represented by the string "W".

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

Figure 1

012
0RoseWTulip
1WDaisyW
2LilyWOrchid

Daily care routines require you to identify if the garden is becoming overgrown.

The subroutine should:

  • Take the 2D array garden as a parameter
  • Count the number of "W" elements in the array
  • Output the word "Overgrown" if there are five or more "W" elements in the array
  • Output the total number of "W" elements if there are fewer than five.

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 3x3 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)