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

Instructions ch7.Ex9Data.txt main.cpp + 1 iller, Jason Brian 2 Blair, Lisa Maria

ID: 3755526 • Letter: I

Question

Instructions ch7.Ex9Data.txt main.cpp + 1 iller, Jason Brian 2 Blair, Lisa Maria 3 Gupta, Anil Kuma 4 Arora, Sumit Sahil 5 Saleh, Rhonda Beth Instructions You are given a file consisting of students' names in the following form: lastNane firstNane middleNane . (Note that a student may not have a middle name.) Write a program that converts each name to the following form: firstNane middleNane lastNane Your program must read each student's entire name in a variable and must consist of a function that takes as input a string, consists of a student's name, and returns the string consisting of the altered name. Use the string function find to find the index of; the function length to find the length of the string; and the function substr to extract the firstName, middleName , and lastNane

Explanation / Answer

Please give aThumps Up if you like the answer

Program

#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>

using namespace std;

void getName();


int main()
{
getName();
system("pause");
return 0;
}

void getName()
{
string fullName;
ifstream inFile;
string lastName;
string otherName;
string firstName;
int junk;
int otherJunk;
inFile.open("nameconversion.txt");
do
{
  getline(inFile, fullName);
  junk = fullName.find(",");
  lastName = fullName.substr(0, junk);
  otherJunk = fullName.length();
  firstName = fullName.substr(junk + 2, otherJunk);
  cout << firstName << " " << lastName << endl;
}
while (inFile.eof() == false);
inFile.close();
}

nameconversion.txt

Miller, Jason Brian
Blair, Lisa Maria
Gupta, Anil Kumar
Arora, Sumit Sahil
Saleh, Rhonda Beth

Output

Jason Brian Miller
Lisa Maria Blair
Anil Kumar Gupta
Sumit Sahil Arora
Rhonda Beth Saleh
Press any key to continue . . .