1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include "Project2.h"
void weatherSummary ( string inputfile, string outputfile )
{
ifstream in("input.txt"); // read the data from the input file
ofstream out("output.txt"); // send my data to an output text file
string name;
int latitude;
int longitude;
int elavation;
int TPCP;
int MNTM;
in.ignore(5000, '\n'); //ignore the header
readData( in, string &name, int& elavation, int& latitude, int& longitude, int& TPCP, int& MNTM );
while( !in.fail() )
{
out << name << "," << elavation << "," << latitude << "," << longitude
<< "," << TPCP << "," << MNTM << endl;
readData( in, string& name, int& elavation, int& latitude, int& longitude, int& TPCP, int& MNTM );
}
}
void readData(ifstream& in, string &name, int& elavation, int& latitude,
int& longitude, int& TPCP, int& MNTM )
{
string junk;
getline( in, junk, ',' );//read from in, store in junk and stop
//at the comma - and get rid of the comma in the process
getline( in, name, ',' );
in >> elavation;
in.ignore( 500, ',');//ignore the list of namespace
in >> latitude;
in >> longitude;
in.ignore( 500, ',' );//ignore the date line
in >> TPCP; //read the TPCP data
in.ignore(500, ',');//ignore the missing line
in.ignore(500, ',');//ignore the consecutive line
in >> MNTM;//get the data for temperature
in.ignore (5000, '\n' );// ignore the rest of the line
}
int main ()
{
weatherSummary( "US_partial.cvs", "output.cvs");
readData( string& name, elavation, latitude, longitude, TPCP, MNTM );
return 0;
}
|