Homework One
Averaging a huge list

This is a warm-up exercise to refresh your memory on how to read and write files in C++.


The data file lab1.dat contains tide data from the Texas Coastal Observation Network. The file contains primary water level (pwl) readings for the Texas State Aquarium (station number 008 ) for the week of January 6 to January 12, 2011. The readings are recorded in meters at 6 minute intervals.

Each line of the data file uses the same format:
      station_number date_time data_type data data data data...

Station numbers are always a 3 digit number.

The time stamp is recorded as "Year", "Day of Year", "+", "Time". For example, "2011006+0000" is year 2011, day 6, hour 0. In other words, midnight on Jan 6, 2011. As another example, "2011006+2300" is 11:00pm on Jan 6, 2011.

The code "pwl" indicates Primary Water Level.

After the header information on each line, there are 10 floating-point numbers, which are the water level readings. The first number is time + 0 minutes, the second number is time + 6 minutes, then 12 minutes after the hour, then 18, 24, 30, ... 48, and 54.

As an example, here is one line from the data file:
      008 2011006+1400 pwl 1.475 1.474 1.472 1.470 1.468 1.466 1.464 1.462 1.459 1.457
The station is 008, the date is Jan 6, 2011, and the time is 2:00pm. So, at 2:30pm the water level was 1.466 meters.


For this assignment, write a C++ program to read the file "lab1.dat" and average the water levels for each day. Write the daily averages to the file "lab1.out", one average per line, each line starting with the day code.

In other words, read the file above and create a file with something very similar to this:

2011006   1.45073
2011007   1.38101
2011008   1.42564
2011009   1.56272
2011010   1.59882
2011011   1.53139
2011012   1.42280
So, on Jan. 6 the average water level was 1.45073.

For this assignment you can assume the data file is not corrupted. For example, when a TCOON station goes down, data is recorded as the text NA instead of as a number. But, this data file will have no such abnormalities.

You can assume the data file is always 7 days of data. 24 hours per day...

You can not assume the data file is always January 6 through January 12.

You should not assume opening of the files lab1.dat and lab1.out is always successful.


Submit your source code via email to dannellys@winthrop.edu with the subject line CSCI325 - HW 01 by 2:00pm on January 25.