/* Name: Christopher Walck Course: cis 136 020 Assignment: Project 1 Due Date: February 6, 2003 Description: The following program reads the contents (a list of states and their attributes) of a file (States.data.txt), sorts the information alphabetically by the state's name, and prompts the user to search for a state. If the user's searchterm is found the state's name and its attribute's are output to both the screen and a file names statelog.txt. Otherwise, a "contents not found" message if output to both the screen and the afore mentioned file. */ #include #include #include #include #include using namespace std; struct Date { int admittMonth, admittDay, admittYear; }; struct State { string stateName, stateCapital; int popRank, areaRank, admittOrder; Date stateDate; float popDensity; long ttlPopulation, area; }; struct StateIndex { int position,size,nameLen; }; typedef vector IndexList; // function sorts the data input from States.data.txt from // the largest (that is, the string with the greatest ASCII // value) to the smallest. void sortList(int ttlStates, State list[]) { for (int index = ttlStates - 1; index > 0; index--) { int maxIndex = index; for (int idx = 0; idx < index;idx++) if (list[maxIndex].stateName < list[idx].stateName) maxIndex = idx; if (maxIndex != index) { State temp; temp = list[maxIndex]; list[maxIndex] = list[index]; list[index]=temp; } } } // function reads one 'State' struct from the file States.data.txt void readStatesFile(State& list, ifstream& Source) { char nullToken; getline(Source,list.stateName); cout << "Name:" << sizeof(list.stateName); Source>>list.ttlPopulation; cout << " Pop:" << sizeof(list.ttlPopulation); Source>>list.popRank; cout << " PopRank:" << sizeof(list.popRank); Source>>list.popDensity; cout << " PopDensity:" << sizeof(list.popDensity); Source>>list.area; Source>>list.areaRank; Source>>list.stateDate.admittMonth; Source>>list.stateDate.admittDay; Source>>list.stateDate.admittYear; cout << " Date:" << sizeof(list.stateDate); Source>>list.admittOrder; Source.get(nullToken); //used to get the blank before the stateCapital getline (Source, list.stateCapital); } // function prints one 'State' struct to either // the screen or a file (see actual parameters of // Destination. void printState(ostream& Destination, State& list) { Destination.setf(ios::left); Destination<