// Lab1-EarthQuake.cpp #include #include #include using namespace std; class EarthQuakeRecord { private: static const int nYEAR=0, nMONTH=5, nDAY=8, nHOUR=11, nMINUTE=14, nSECOND=17; int nYear, nMonth, nDay, nHour, nMinute, nSecond; static const int nLATITUDE=31, nLONGITUDE=38, nMAGNITUDE=45; double dLatitude, dLongitude, dMagnitude; static const int nDEPTH=50; int nDepth; static const int nCITYLATITUDE=64, nCITYLONGITUDE=72; double dCityLatitude, dCityLongitude; static const int nSTATEPROVINCE=87; int nStateProvince; static const int nCITYNAME=93, nDATASOURCE=125; string sCityName; public: EarthQuakeRecord() { } void ParseInput(char* pszRawRecord) { nYear = atoi(pszRawRecord); nMonth = atoi(pszRawRecord+nMONTH); nDay = atoi(pszRawRecord+nDAY); nHour = atoi(pszRawRecord+nHOUR); nMinute = atoi(pszRawRecord+nMINUTE); nSecond = atoi(pszRawRecord+nSECOND); dLatitude = atof(pszRawRecord+nLATITUDE); dLongitude = atof(pszRawRecord+nLONGITUDE); dMagnitude = atof(pszRawRecord+nMAGNITUDE); nDepth = atoi(pszRawRecord+nDEPTH); dCityLatitude = atof(pszRawRecord+nCITYLATITUDE); dCityLongitude = atof(pszRawRecord+nCITYLONGITUDE); nStateProvince = atoi(pszRawRecord+nSTATEPROVINCE); char* pcStartOfCityString = pszRawRecord+nCITYNAME; char* pcEndOfCityString = pszRawRecord+(nDATASOURCE-1); while (pcEndOfCityString > pcStartOfCityString && *pcEndOfCityString == ' ') pcEndOfCityString--; *(pcEndOfCityString+1) = '\0'; sCityName = pcStartOfCityString; } }; class EarthQuakeDataSet { private: int nMaxRecords; int nNumRecords; EarthQuakeRecord* pEarthQuakeRecords; public: EarthQuakeDataSet() { cout << "Number of records to process:"; cin >> nMaxRecords; pEarthQuakeRecords = new EarthQuakeRecord[nMaxRecords]; char szFileName[256]; cout << "Filename: "; cin >> szFileName; ifstream ifsInputFile(szFileName); char szRawRecord[128]; for (nNumRecords = 0; ! ifsInputFile.eof() && nNumRecords < nMaxRecords; nNumRecords++) { ifsInputFile.getline(szRawRecord, 127, '\n'); pEarthQuakeRecords[nNumRecords].ParseInput(szRawRecord); } ifsInputFile.close(); } ~EarthQuakeDataSet() { delete [] pEarthQuakeRecords; } }; void main() { EarthQuakeDataSet eqdsUSHistoricalData; }