Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C++, given a file consisting of student\'s names in the follwing form: lAS

ID: 3886547 • Letter: U

Question

Using C++, given a file consisting of student's names in the follwing form: lASTNAME, fIRSTname middleName, write a program that: (1) converst each name to the following form while Removing the comma; firstName middleName lastName, (2) Program must read each student's name in a variable and must consist of a function that takes as input A string consisting of the alterd name (first middle last). (3) Use the string function FIND to find the index of the , (comma). the function length to find the length of the string, and the function SUBSTR to extract the firstName, middleNme, and lastName. See following for anticipated format of code with general expectation (must have return string):

#include <iostream>

#include<string>

#include<fstream>

Using namespace std;

Ifstream infile;

Ofstream outfile;

String removeComma(string str)

Int main()

{

Cout<<”hello!”<<endl;

String str;

Infile.open (“data.txt”);

Outfile.open(:Display.txt”);

While (1infile.eof())

Infile >> str;

{int pos=str.find(‘,’);

String beforeComma = str.substr(o, pos);

Int Len =str.length-pos-1;

String aftercomma= str.substr(pos +1);

Infile.close();

Outfile.close();

Return0;

}

Explanation / Answer

// C++ code

#include<iostream>

#include<fstream>

#include<string>

using namespace std;

int main ()

{

string firstName, middleName, lastName;

string line;

ifstream infile;

ofstream outfile;

infile.open ("data.txt");

outfile.open ("Display.txt");

while (getline(infile, line))

{

int comma = line.find (',');

int length = line.length ();

lastName = line.substr (0, comma);

int space_after_firstName = line.find (' ', comma + 2);

if (space_after_firstName != -1)

{

firstName = line.substr (comma+2, space_after_firstName - comma -2);

middleName = line.substr(space_after_firstName + 1, length);

outfile << firstName << " " << middleName << " ";

cout << firstName << " " << middleName << " ";

}

else

{

firstName = line.substr (comma+2, length);

outfile << firstName << " ";

cout << firstName << " ";

}

outfile << lastName << endl;

cout << lastName << endl;

}

system("pause");

return 0;

}



input data file format
kyle, Clarke M

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote