CS120
Lab #8

Due at the end of lab.

For this lab you will be reading in and analyzing a set of data. The data file is in the file weather.txt. You should begin by opening the file with nano (or another text editor) and examining the format of the data inside the file - note that it contains the weather for Moscow, ID for all of January 2021.

For this lab you need to write a program to read in the data and perform the following calculations:

To read in a data file, you need to open the file using the fstream library, so include the fstream library the same way you include the iostream library. Then add an input file stream object of the class ifstream and connect it to the weather file:
ifstream infile; // this creates an ifstream object called infile
infile.open("weather.txt"); // this connects infile to the text file
Then you can read from the file using infile:
infile >> x;
Note that the >> symbols are used just as with cin, but now the data is coming from a file rather than the keyboard.

The weather.txt file contains 8 columns of data (if the date is treated as 3 columns). So you may want to create 8 separate arrays, one for each column. Alternatively, you could create fewer arrays and "throw away" data that you don't need - i.e. read it into a variable and then ignore that variable. This would be a reasonable approach with the columns containing just "jan" and "2016" values because you don't need them to perform the required calculations.

Note that the code to read in the data may look something like:
for(int i = 0; i < number of rows; i++){
infile >> array1[i];
infile >> array2[i];
infile >> array3[i];
...
There is also the problem of the first row, which is the column headers. One simple way of dealing with this row is to simply create another data file and delete that row from it, then read in the modified file since your program won't really need the column headers. A second approach is to begin by using the infile.getline() function to read the whole first row containing the column headers as one long string (and ignoring it) before reading in the rest of data.

Turn in: A copy of the code for your program and sample output showing it runs. Place your sample output in a file named Lab8output.txt. As always, if you cannot finish all of the functionality turn in as much as you complete - as long as your code compiles and runs. Turn in a copy of your program code and your Lab8output.txt file to Canvas.