Lab 10. Arrays



Monthly Rainfall

Write an application that draws a graph of the rainfall by month for a particular city.

You will use an array of integers to hold each month's rainfall in inches. For this exercise, we will use the Rnd() function to fill the array with integers between 0 and 10.

You will need the following controls to complete today's lab:

You will need at minimum the following variables to complete today's lab:


Button click event algorithms

Get Rainfall

This button fills the array with random integers between 0 and 10 inclusive.

   For 0 to UBound of array
      fill element with random integer: Int(Rnd() * 11)
   Next

Graph

This button draws a bar graph based on the values in the array. You should draw a blue rectangle for each month except the month(s) with the highest amount of rainfall. The month(s) with the highest amount of rainfall should have a red rectangle as seen in the example above.

   get max value of array (use a max function that passes in the array and returns the max value).

   For 0 to Ubound of array
      If element equals max Then
          fill red rectangle (see below)
      Else
          fill blue rectangle (see below)
      End If
      Draw black outline of rectangle
      Draw number of inches above rectangle(use CreateGraphics.DrawString function)
   Next

Print Stats

This just outputs the total inches for the year and the average monthly rainfall to the label.

   get total number of inches for year (use a total function that passes in the array and returns the total of all values in the array).
   output to the label the total and then a newline (vbNewLine)
   output to the label the average (total / array.Length)

How to draw/fill rectangles using a For loop

A rectangle needs a SolidBrush, x coordinate, y coordinate, width, and heigth.


How to draw the # of inches above each bar

Use the DrawString function. The DrawString function needs a String output, a Font object, a SolidBrush object, an x coordinate, and a y coordinate.