Conceptual Question: using Arrays in C++

Yes, this is part of a hw problem for class but I just need help in understanding where to go with this, not actual code. I'm given a file that lists lat and long data for states, as well a line that indicates the state (sample shown). The goal is to create a program, using arrays only I believe (not structs), that asks a user to input the state in the command line and the program draws the outline of the state in a window based on the coordinates (drawing is done via a custom library they provide us). I understand the basics of inputing data into an array but I'm at a loss of how to go about dealing with the state labels, and how/if the labels are used selecting the correct data to draw with. Any help would be appreciated. thanks

Or combine the coordinates:
float coordinates[51][MAXPOINTS][2]; //0 is for latitude, 1 is for longitude

Then when the user enters the abbreviation you find the position in the co-arrays then display based on that. Probably write a function that takes the coordinates for the one state to format for display.

Read and ignore lines until the desired state abbreviation appears on a line by itself.
Read, parse, and draw lat/lon pairs until terminator appears (-1 -1).
Halt.

The "Parallel Arrays" approach.

Read a line. Does it look like a state abbreviation or a lat/lon pair?

If a state abbreviation, store it in an array of state abbreviations,
then commence reading lat/lon pairs into an array of lat/lon coords
for this state, stopping at terminator.
Store that array into another parallel array.

"Parallel array" means an array with a different name and type than the state-name array, but whose items have the same index as the corresponding state name. So the name for AK is at index 0, and the array of coords for AK is also at index 0, but in a different array. (This is a BF&I approach to structuring data, when structs or objects are much clearer and more encapsulated. It's the kind of BS you'd do in old-school BASIC programs where the only composite data structure was an array.)

And I'm wondering what the data for Michigan looks like, or really any state with islands or discontiguous land areas.

(This is a BF&I approach to structuring data, when structs or objects are much clearer and more encapsulated. It's the kind of BS you'd do in old-school BASIC programs where the only composite data structure was an array.)

Click to expand...

LOL. You got me remembering about BASIC as soon as I saw parallel arrays.

In the interests of KISS, I would recommended chown33's first BF&I approach, considering the state is one the command-line and the program won't have to make multiple lookups.

If the OP gets that to work, fork the code and try to the parallel arrays approach. Lee's given you the data structures for this. But really I wouldn't bother. For reals, you wouldn't do it this way.

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.