/*************************************************** Print *town* names from census data Final Census data looks like (e.g. 24md.txt): Table 3. Land Area, Population, and Density for Places in Maryland: 1990 Source: US Census Bureau Release date: May 1996 FIPS CODES POP PER POP PER ST PLACE POP SQ.KI. SQ.MI. SQ.KI. SQ.MI. NAME 24 00125 13,087 13.7 5.3 955.8 2475.6 Aberdeen town 24 00175 5,267 28.2 10.9 186.8 483.8 Aberdeen Proving Ground CDP Note: everything is town, city, village, or CDP 1. Simplified data (1 row: census1.txt) 24 04625 530 0.6 0.2 870.3 2254.0 Barton town 2. Little more complex (census2.txt) 24 05550 8,860 6.7 2.6 1329.1 3442.5 Bel Air town 3. Multiple rows (census3.txt): 24 00125 13,087 13.7 5.3 955.8 2475.6 Aberdeen town 24 00175 5,267 28.2 10.9 186.8 483.8 Aberdeen Proving Ground CDP 24 00225 349 1.3 0.5 271.6 703.4 Accident town 24 00250 4,477 58.0 22.4 77.2 199.8 Accokeek CDP 4. Deal with header (24md.txt) ***************************************************/ #include #include #include using namespace std; int main23() { // Open the file ifstream fin("24md.txt"); // Skip the HEADER string junkStr; fin >> junkStr; while (junkStr != "NAME") { fin >> junkStr; } // Process each entry fin >> junkStr; // read first junk entry while (fin) { // stop when no more lines string name, cityType, temp; // skip rest of the 6 fields I don't care about fin >> junkStr >> junkStr >> junkStr >> junkStr >> junkStr >> junkStr; // Get name and type fin >> name; fin >> temp; while ( temp != "city" && temp != "town" && temp != "CDP" && temp != "village") { name = name + " " + temp; // add on new word to the name fin >> temp; } cityType = temp; if (cityType == "town") { cout << name << " is a town" << endl; } fin >> junkStr; // read first junk entry - MUST trigger error!! } return 0; }