Classwork 15: April Weather Report


Objectives

More practice working with arrays.


Background

Was yesterday, April 23rd, colder than January? Not quite. The average temperature yesterday was 44F. The average temperature for January was 38F according to the Wunderground website. Still, yesterday was pretty cold for April in Baltimore.


The Assignment

Your assignment is to write a program that tells the user how cold it is compared to historical data. You will progress step by step. Make sure that at the end of each step that you have a program that compiles and runs.


Step 1: Copying

Copy the file: april.c

This program initializes 3 arrays: mean[], max[] and min[]. They contain the historical average temperatures for the month of April as observed at BWI Airport. For example, max[4] has the average maximum temperature for April 5th. Note that the array indices are off by one compared to the dates!! This value was averaged over a certain number of years. That is, they went through historical data and took all the highest temperatures observed for April 5th of each year and calculated the average maximum temperature for April 5th. Similarly, mean[] has the average average temperature for each day in April and min[] has the average minimum temperature.


Step 2: Simple Report

Expand the program to ask the user for the current day in April and the observed temperature. Print out a different message depending on whether the observed temperature is:

For example, when the temperature is lower than the min, you might say:


  Wow, 44 degrees is colder than the average minimum of 45 for April 23!

Compile and test your program to make sure that it works. Do not proceed to the next step until you have done so.


Step 3: Monthly Average

Use a for loop to calculate the monthly average mean, maximum and minimum temperatures for April. This should be a simple for loop that iterates through each array and computes the sums of the values. After the sums have been computed, dividing by 30 gives the monthly average (because April has 30 days). Your output might look something like:


For the month of April, the average mean temperature is: 53.566667F.
For the month of April, the average max temperature is: 64.600000F.
For the month of April, the average min temperature is: 42.633333F.

Compile and test your program to make sure that it works. Do not proceed to the next step until you have done so.


Step 4: Part Month Averages

There is actually significant variation in average temperatures in April. The average mean for April 1st is 49F while the average mean for April 30 is 58F.

Expand your program so that it reports the average mean for the first 10 days of April (April 1 through April 10) or the middle 10 days of April (April 11 through April 20) or the last 10 days of April (April 21 through April 30).

For example, if the user specified the 19th of April, your program should say something like:


The average mean temperature for the middle of April is: 53.700000F.


Submit

When you are done testing your program, use the script command to record yourself compiling the program and running it on several test cases. Then, submit as usual:


submit cs104_chang cw15 april.c typescript