This lab will introduce you to reading data into and processing data contained within two-dimensional arrays. In this lab, you will take in data representing the highest/lowest temperatures for each month of the year. You will then find the minimum/maximum temperature for the year and the average low/high temperature for the year.
In this lab you will write a program that uses two-dimensional arrays to store data from a text file in main memory. The data from the text file you will be storing holds the high and low temperatures for each month of the year. You will:
To do these 5 tasks you will need to start by reading the data from a TXT file into a two-dimensional array. In order to do this you will prompt, to the command line, your user to enter a TXT file name. You will then attempt to open the TXT file name the user enters, if you are unable to open the TXT file name the user enters, output an error and loop until the user enters a valid file name. The error you will output is:
Error: Invalid input file name.
Once you have your data stored into a two-dimensional array you can process the information in it to get the statistics you need for this lab. To retrieve these statistics we will write 3 functions described below.
In our dataset the first column of data will contain the low temperatures for each month of the year. Create a function:
float lowestTemp (float[][2])
Which takes in a two-dimensional array that is n x 2 in size, where n is the amount of rows in the two-dimensional array, and returns the lowest floating point number in the first column (Note: the 2 in the formal parameters denotes 2 columns).
In our dataset the second column of data will contain the high temperatures for each month of the year. Create a function:
float highestTemp (float[][2])
Which takes in a two-dimensional array that is n x 2 in size, where n is the amount of rows in the two-dimensional array, and returns the lowest floating point number in the first column (Note: the 2 in the formal parameters denotes 2 columns).
Create a function:
float averageLowTemp (float[][2])
Which iterates through the first column of data in the passed two-dimensional array and finds the average of the column.
Create a function:
float averageHighTemp (float[][2])
Which iterates through the second column of data in the passed two-dimensional array and finds the average of the column.
Once you have completed the above functions you can use them to match the example output. The order to call each function above to get values to match the example output is:
An example of an interaction with your program is shown below, your output should match these examples exactly. (The words printed in blue are from the computer, based on your commands, the words in red are user input. Note: these colors are simply here to distinguish components and not needed in your program.):
Alexs-iMac:lab12 alex$ ./a.out
TEMPERATURE STATISTICS
What is the data file name?
**error
Error: Invalid input file name.
What is the data file name?
**error.txt
Error: Invalid input file name.
What is the data file name?
**Lab12Data.txt
Henderson 2019
Lowest temperature of the year was 35.2 F.
Highest temperature of the year was 115.5 F.
Average low temperature of the year was 56.55 F.
Average high temperature of the year was 84.66 F.