Suppose a meteorology station records the temperature and humidity every hour of every day and stores the data for the past ten days in a text file named weather.txt (copy from shared directory).
Each line of the file consists of four numbers that indicate the day, hour, temperature, and humidity. The contents of the file could be like:
1 1 76.4 0.92
1 2 77.7 0.93
. . .
10 23 97.7 0.71
10 24 98.7 0.74
Note the lines in the file are not necessarily in increasing order of day or hour. For example, the file could appear as shown below:
5 23 77.7 0.93
9 8 77.7 0.93
. . .
5 18 77.7 0.93
2 23 77.7 0.93
Your task is to write a program that calculates the average daily temperature and humidity for the ten days. Open and read the file using an ifstream object into a three-dimensional array named data. The first index of data ranges from 0 t 9 and represents 10 days; the second index ranges from 0 to 23 and represents 24 hours; and the third index ranges from 0 to 1 and represents temperature and humidity, as depicted below.
Data [ day ] [ hour ] [ temperature|humidity ]
Note the days are numbered from 1 to 10 and the hours from 1 to 24 in the file. Because the array index starts from 0, data[0][0][0] stores the temperature for day 1 at hour 1 and data[9][23][1] stores the humidity for day 10 at hour 24.
Hints:
Sample output
Day Avg Temp Avg Hum
0 77.770800 0.929583
1 77.312500 0.929583
. . .
9 79.354200 0.912500