Hi,everyone! I have to write a program that can find zip codes.
I have to read the codes from a txt. file, so i have to use struct arrays
In the main program, I just have to enter any random zip code and the program should be able to tell from which city or state it is.
My deadline is tomorrow so sample codes will be appreciated
THANKS!!

How is the file formatted? Does it contain fixed or random length records? Binary file or text file? We have to know everything about the file before your question can be answered.

It's a text file and here is just sample of what it looks like;) German cities and zip codes)

thagen;;18182;038202;Mecklenburg-Vorpommern Wietmarschen;;49835;05925;Niedersachsen Wietow;;23966;03841;Mecklenburg-Vorpommern Wietstock;b Ludwigsfelde;14974;03378;Brandenburg Wietstock;b Torgelow, Vorpommern;17379;039777;Mecklenburg-Vorpommern Wietze;;29323;05146;Niedersachsen Wietzen;;31613;05022;Niedersachsen Wietzendorf;;29649;05196;Niedersachsen Wiggensbach;;87487;08370;Bayern Wilburgstetten;;91634;09853;Bayern Wildau;b Königs Wusterhausen;15745;033762;Brandenburg Wildau-Wentdorf;, NL;15938;035453;Brandenburg Wildberg;b Herzberg, Elster;04916;035362;Brandenburg Wildberg;b Neustadt, ............

Please explain the format of that file. Looks like <city nbame>;;<zip code>;<some other number, don't know what>;

your search algorithm will probably look something like this:

bool found = false;
int index = 0;

cout << "Enter random zip code: ";
cin >> zip_code;

for(int i=0; i < max_number_of_cities; i++)
{
     if(zip_code == mystruct[i].zip)
     { 
          found = true;
          index = i;
          break;
     }
}

if(!found)
{
     cout << "zip code not found in database.";
}
else
{
     cout << "the zip code " << zip_code << " is for " << mystruct[index].city_name;
}

city name;zip code; dialing code
thanks

Can you please suggest an algorithm that uses pointers and I also have to read and save the text file, which I#m having trouble with. Here is a rough translation of the task into English(I used google translator so it's bit jumbled, my german's not that good):

Define a structure with two pointers to strings for each of the cities and the additional info. Set your internal memory for the data field with 100,000 array elements that are of this type of structure. Use the zip code as an index, for example, are stored in the array element with index [47 057] is a pointer to the string "Duisburg" and a null pointer for the addition or in the array element with index [45 472] is a pointer to the string "Mülheim" for the place and a pointer to the string "at the Ruhr for the addition. You needn't disk space, may be applied to places that are available with several postal codes, create their own strings for the name of the place and the additional info. The advantage of using such a field is that when you sort reading the data virtually to the zip code in time O (n) (this sorting method is called multiple distributors) and the search for data in super-fast constant time O (1) takes place.

why are you even taking this class..

@ Clinton whatever :If your not interested in being helpful, go do something else worth your while...

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.