/* 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 #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; int main() {IndexList idx; StateIndex sIdx; fstream binFile("states.bin",ios::in|ios::out|ios::binary); binFile.seekg(-604,ios::end); for (int i=0;i<50;i++) { binFile.read((char *)&sIdx,12); idx.push_back(sIdx); } char name[15],cap[15]; for (int k=0;k<50;k++) { memset(name,0,15); memset(cap,0,15); // null out the strings binFile.seekg(idx[k].position); binFile.read((char *)&name,idx[k].nameLen); binFile.seekg(36,ios::cur); binFile.read((char *)&cap,idx[k].size-idx[k].nameLen-36); cout.setf(ios::left); cout << setw(15) << name << setw(15) << cap << endl; } }