The Data in the file was given in a csv file like this but there were a lot more
ID: 3804194 • Letter: T
Question
The Data in the file was given in a csv file like this but there were a lot more rows:
Cross Shaina 12 Corrigan Ct Benicia CA 94510-2578 12.25 10.25
Weiner Alysha 1748 Legend Cir Vacaville CA 95688 10.25 14
Son Bernardo 1031 Rodondo Avenue Oakley CA 94561 10.25 21
Pearce Georgene 1005 Bayside Ct Fairfield CA 94533-3147 13 21.75
Doucette Ted 1115 Estes Ct Suisun City CA 94585 10.5 16.5
Spooner Denny 2530 Gina Ct Vallejo CA 94591-4934 15.5 21
Galbraith Santos 307 Amberwood Circle Fairfield CA 94533-1681 10.5 13.5
Castellanos Kristyn 165 Hayes St Fairfield CA 94533 8.25 20.5
Jue Martin 419 Tulip St Fairfield CA 94534 18.25 25.25
Tucker Olga 209 Pine Valley Drive Fairfield CA 94533-2301 20.25 12.5
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream inFile;
string szSourcePath = // path of input file, change to your file location, if necessary
"test.csv";
ofstream outFile;
string szDestPath =
"out.csv"; // path of output file, change to your file location, if necessary
string szLastName;
string szFirstName;
string szAddress;
string szCity;
string szState;
string szZip;
string szWage;
string szHours;
string szPay;
inFile.open(szSourcePath);
outFile.open(szDestPath);
// this code reads the first line of the input file only
// insert loop to read entire file here
getline( inFile, szLastName, ',');
getline( inFile, szFirstName, ',');
getline( inFile, szAddress, ',');
getline( inFile, szCity, ',');
getline( inFile, szState, ',');
getline( inFile, szZip, ',');
getline( inFile, szWage, ',');
getline( inFile, szHours, ' ');
// calculate pay here
// insert write to output file here
inFile.close();
outFile.close();
system("Pause");
return 0;
}
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream inFile;
string szSourcePath = // path of input file, change to your file location, if necessary
"test.csv";
ofstream outFile;
string szDestPath =
"out.csv"; // path of output file, change to your file location, if necessary
string szLastName;
string szFirstName;
string szAddress;
string szCity;
string szState;
string szZip;
string szWage;
string szHours;
string szPay;
inFile.open(szSourcePath);
outFile.open(szDestPath);
// this code reads the first line of the input file only
// insert loop to read entire file here
getline( inFile, szLastName, ',');
getline( inFile, szFirstName, ',');
getline( inFile, szAddress, ',');
getline( inFile, szCity, ',');
getline( inFile, szState, ',');
getline( inFile, szZip, ',');
getline( inFile, szWage, ',');
getline( inFile, szHours, ' ');
// calculate pay here
// insert write to output file here
inFile.close();
outFile.close();
system("Pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.