Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which finds and returns a struct which contains the month with the highest temperature, and another function to do the same with the lowest temperature. The main program should output the highest and lowest temperatures for the year, along with the month names that correspond to those temperatures.
- The program should define a struct that holds a month name, a low temperature (an int) and a high temperature (an int).
- The program should define an array of such structs. The number of elements in that array should be established using a named constant of type int. This value should be sufficient to store all of the data records from the provided data file.
Your program MUST use the following functions:
- Function loadData: The function reads and stores data in the
parallel array and 2D array from a text file (temps.txt).
int loadData( ifstream &infile, Temperature , int &rows )
(Note that the last parameter returns the number of rows of data actually read from the file.)
- Function findLow: This function finds the month that has the
lowest temperature and returns a copy of the struct containing that
Temperature findLow( Temperature , int rows )
- Function findHigh: This function finds the month that has the
highest temperature and returns a copy of the struct containing
Temperature findHigh( Temperature , int rows ):
- The main program should display a brief description of the program.
- The main program should report the number of months of data read from the file.
- The main program should not call the High and Low functions if the number of rows is less than 1.
- Do not use any global variables. (All variables must be declared inside functions.)
- You must use all the given function prototypes and not change them. You can add more functions if you like.
- The first thing each function should do is announce that it has been called, after which it should display no other output.
- Use a while loop to read all lines of text from the input file.
- LoadData( ) should include code to prevent the arrays from being exceeded.
- The loadData function should return 0 if no error occurred or a nonzero number if an error occurred.
- The program should return an error if the file could not be opened.
- Keep the input file in the same directory as your project.
This program finds the warmest and coldest months as listed in a data file. KloadData called) found 12 months of data KaverageHigh called> The highest average temperature was KaverageLow called The lowest average temperature was in in Process returned 0 (Ox0) Press any key to continue. execution time: 0.140 s