The National Weather Service maintains a database of temperatures for major cities. You will find a fictional copy of part of this database for one day in the file: temperatures.txt which is part of this assignment. Each line in the file contains a city, the low temperature for the day, and the high temperature for the day.
Your first task is to write a program which reads this file into three parallel arrays in memory. One array contains the cities, and the other two arrays contain the high and low temperatures. The arrays are ‘parallel’ in the sense that the n-th element of the cities array contains the city associated with the n-th element of the temperature arrays. Although the data in the test file describes only a few cities you should dimension your arrays for an arbitrary number of cities in the live data file (which may be different from the test file). The size of the arrays should be defined in your program by the declaration const int ARRAY_SIZE = 1000.
For the purpose of this assignment (so as not to make it too complicated) you should declare your three arrays at file scope (i.e. outside any function and before the function main()). The declarations should be as follows:
Write a function whose signature is as follows:
int LoadData ()
The function LoadData should prompt the user for the file path to the data file. If it cannot open the file for some reason, it should return a value of -1 as an error result. Otherwise it should read the data in the file into the three parallel arrays, and return the number of city records that it read.
Now write a function whose signature is as follows:
void ShowAll (int count)
The parameter count provides the number of cities actually stored in the database (i.e the value returned by the function LoadData()). ShowAll() should read the designated number of records in the parallel arrays and display it on the screen in the order it appears in the database, in single column format. In this display format the low and high temperatures appear in parentheses following the city name, and there is one city record per line of output. For example, using the data in the sample file, the output would look like this:
Katmandu (-34, 28)
Perth (92, 105)
Chicago (22, 45)
St. Petersburg (19, 37)
Now test your work so far, by writing a main() function to prompt the user for the path to the data file, open and read the file to the parallel arrays using the function LoadData() (providing error messages and recovery as appropriate if the file doesn’t exist). Then display the contents of the file using ShowAll().
Extend your program into a menu driven application to query the database. When the program starts it should ask the user for the path to the data file, and read the data into the parallel arrays, as in step 1.
Then it should enter a loop, in each iteration of which it prompts the user for what they want to do. The actions are as follows depending on how the user responds to the prompt. See the sample dialog below to see how this works in practice.
Note: In the example below, the user’s input is in red BOLD. The program output is not. See image.
// These declarations should be at file scope
const int ARRAY_SIZE = 1000;
// Function prototypes
void ShowAll(int count);
int ShowCities(int count, string name);