Here is my assignment. I would like someone to walk thru some of this with me if you have time today. This is my last assignment and I just dont understand parallel arrays and how to recall information. If someone could help me get started that would be a big help.

Assignment:

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.

Step (1)

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:

string city[ARRAY_SIZE];
double lowTemp[ARRAY_SIZE];
double highTemp[ARRAY_SIZE];

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().

Step (2)

Extend your program into a menu driven application. It should enter a loop upon startup, where it prompts the user with the following menu:

(L)oad File, (S)how All, (F)ind City, (Q)uit:

The actions are as follows:

• L or l: Prompt the user for the path to the data file, and read the data into the parallel arrays. If this choice is selected multiple times, the data should replace any data currently in the arrays from the previously loaded file(s).

• S or s: The program displays all the records in the database using the function ShowAll you have already developed in step (1).

• F or f: Find the specified city(s). The program displays all records which contain the designated text somewhere in the city field, in a case insensitive manner (upper or lower case should both work). You should use a function with the following signature for this purpose: int ShowCities(int count, string name). This function should display all records whose city field contains the string passed in the parameter called name. It returns the number of records displayed. count specifies the number of records in the database.

Hint: Making the search case insensitive adds some complexity to this assignment. Consider converting a copy of each of the strings to either uppercase or lowercase before doing the search. The string.find() function can be used.

• Q or q: Quit. The program terminates.

Sample Dialog
Note: In the example below, the user’s input is in red BOLD. The program output is not.

Welcome to John’s Library Database.

(L)oad File, (S)how All, (F)ind City, (Q)uit: L
Please enter the name of the temperatures file: C:\temperatures.txt
15 record(s) found.

(L)oad File, (S)how All, (F)ind City, (Q)uit: F
City: C
Chicago (22, 45)
Cincinnati (21, 39)
Munich (31, 38)
Zurich (33, 41)
4 record(s) found.

(L)oad File, (S)how All, (F)ind City, (Q)uit: F
City: Katman
Katmandu (-34, 28)
1 record(s) found.

(L)oad File, (S)how All, (F)ind City, (Q)uit: Q

Design Considerations

1) Please display your name and not mine in the welcome message.

2) The following two lines seem to be required to but the file back to a state where it can be opened again it (otherwise, some compilers, like mine, will not allow the file to be reopened):

inFile.close();
inFile.clear(std::ios_base::goodbit);

3) It is an essential part of your grade that you design your application according to the considerations described above. For example, you must use functions that have the specified signatures, and arrays that have the specified declarations. They are as follows:

// These declarations should be at file scope
const int ARRAY_SIZE = 1000;
string city[ARRAY_SIZE];
double lowTemp[ARRAY_SIZE];
double highTemp[ARRAY_SIZE];

// Function prototypes
int LoadData();
void ShowAll(int count);
int ShowCities(int count, string name);

Be more specific about what parts you want help with. Simply posting your assignment is against Daniweb rules because it implies you want your work done for you.

Sorry, I was just about to do that. Is is what I have so far:

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <algorithm>


using namespace std; 

//Declare variables to manipulate data
    char reply;
    string city[ARRAY_SIZE];
    double lowTemp[ARRAY_SIZE];
    double highTemp[ARRAY_SIZE];

//Declare stream variables
    ifstream inFile;
    ofstream outFile;

int LoadData(){
    cin.clear();
    cin.ignore();


    // Prompt user for file location
    string inputFileName;
    cout << "Please enter the full pathname to the data file on disk: ";
    getline (cin, inputFileName);

    ifstream inFile(inputFileName.c_str());

    if(!inFile.is_open())
         return -1;

    int count = 0;

Honestly, that isn't very much and looks like boiler-plate code.

Logically speaking, how to do your assignment is explained quite well in the assignment question, it even goes so far as to tell you what each method should do.

I think I should re-iterate deceptikon's question, could you please be more specific about what you need assistance with?

commented: well put. +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.