Question: C++ Read file lab, USE DRIVER CODE PROVIDED. please separate cppfiles for them. THIS IS THE TXT FILE YOU MUST READ FOR THE PROBLEM: person_csv.txt

C++ Read file lab, USE DRIVER CODE PROVIDED. please separate cppfiles for them.

THIS IS THE TXT FILE YOU MUST READ FOR THE PROBLEM:

person_csv.txt

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

George; Washington ;M ; 2 ; 22 ;1732; Federalist; 1
John ;Adams ;M ; 10 ; 30 ; 1735; Federalist;2
Thomas; Jefferson ;M ; 4 ; 13 ; 1743; Republican; 3
James; Madison ;M ; 3 ; 16 ; 1751;Republican; 4
Abraham ;Lincoln ;M ; 2 ; 12 ; 1809;Republican ; 16
Ulysses ;Grant ;M ; 4 ; 27 ; 1822;Republican; 18
Franklin ; Roosevelt ;M ; 1 ; 30 ; 1882; Democrat 32
Harry ;Truman ;M ; 5 ; 8 ; 1884;Democrat; 33
Dwight ;Eisenhower ;M ; 10 ; 14 ; 1890; Republican; 34
John; Kennedy ;M ; 5 ; 29 ; 1917; Democrat ;35
Richard ;Nixon ;M ; 1 ; 9 ; 1913;Republican; 37
Gerald; Ford ;M ; 7 ; 14 ; 1913;Republican; 38
Jimmy ;Carter ;M ; 10 ; 1 ; 1924; Democrate ;39
Ronald; Reagan ;M ; 2 ; 6 ; 1911; Republican;40
George H. W.; Bush ;M ; 6 ; 12 ; 1924; Replican;41
William (Bill); Clinton ;M ; 8 ; 19 ; 1946; Democrat; 42
George W.; Bush ;M ; 7 ; 6 ; 1946;Replican ; 43
Barack ;Obama ;M ; 8 ; 4 ; 1961; Democrate; 44

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Lab Description: You need to define the class object Person which has

the following in the class object definition file (.h) Class private data

DRIVER FILE

attribute: string firstName, lastName, gender, party; int month, day, year, term Class

OUTPUT

object Person member functions: Person(); initialize all string data members to "N/A"

what person_csv.txt looks like.. I typed it above for you tocopy paste.

and all int data member to 0 Person(string pFirst Name, string pLastName,

Sample test program we did in class.. Doubt this is needed foryou

// reading a text file
#include
#include
#include
#include
#include
#include // used for vector sort
#include // output format setw


using namespace std;


const char SPLIT_CHAR = ';'; // used to parse file with ; asdelimiter

string trim_words(const string & sentence) {
stringstream ss;
string s;
string out;
ss while (ss >> s)
{
out += (s + ' ');
}
return out.substr(0, out.length() - 1);
}


int main(int argc, char* argv[])
{
string str1, str;
vector tokens;
string fname, lname, gender, party;
int month, day, year, term;
string fileName;
// use filename if provided in the parameter list
if (argc {
cout cout fileName ="person_csv.txt";

}
else
fileName = argv[1];
ifstream myfile (fileName.c_str()); // open the file

if (myfile.is_open()) {
while (myfile) {
if (!getline(myfile, str))
break; //end of file

istringstream split(str);
// for (string each; getline(split,each, split_char); tokens.push_back(each));
// OR USE THE WHILE LOOP BELOW
vector tokens;
while (split) // parse the line
{
string s;
if (!getline(split, s,SPLIT_CHAR))
break; // end of line
else
{
str1 = trim_words(s); // removeleading and trailing spaces
tokens.push_back(str1); // puteach splited field into vector
}
}
// now use `tokens`

for (unsigned int i = 0; i {
switch (i)
{
case 0: //field #1 from the line
fname = tokens[i];
break;
case 1: //field #2 from the line
lname = tokens[i];
break;
case2:
gender = tokens[i];
break;
case3:
month = stoi(tokens[i]); // convert field#4
break; //string month to int month
case4:
day = stoi(tokens[i]);
break;
case5:
year = stoi(tokens[i]);
break;
case6:
party = tokens[i];
break;
case 7:
term = stoi(tokens[i]);
}
}
cout }
myfile.close();
}
else
cout

return 0;
}

Lab Description: You need to define the class object Person which has the following in the class object definition file (.h) Class private data attribute: string firstName, lastName, gender, party; int month, day, year, term Class object Person member functions: Person(); initialize all string data members to "N/A" and all int data member to 0 Person(string pFirst Name, string pLastName, string pGender, string pPolical Party, Int pMonth, int pDay, int pYear, int pTerm) string getFname() const; string getLname() const; string getGender() const; string getParty() const; int getTerm() const; int getMonth() const; int getYear() const; int getDay() const; void printPresidentInfo(); Implement all class object member function in class object definition implementation file (.cpp)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!