Can someone help me with this code in C Write a function to

Can someone help me with this code in C++?

Write a function to convert a string containing lastName, firstName middleName to firstName middleName lastName. For example, if the string contains: \"Miller, Jason Brian\", then the altered string should contain \"Jason Brian Miller.\" A data file with names has been provided for testing. Write a driver that reads each line in as a string, uses your function to convert the name and then displays the converted name.

data:

Include:

Analysis at the top of the file

Function analysis, preconditions, and postconditions after each function prototype

Major tasks identified as comments in main function

Comments in functions as needed

Solution

#include <iostream>
#include <fstream>
using namespace std;

//function to convert input as required
//pre-conditions: input line as param
//post-cndiiotns:return changes updated string
void convert(string input)
{
    //declare req variables
    string output=\"\";
    //display input string
    cout<<\"\ Input string: \"<<input;
    //find index of \',\' and update string as requried
    int index=input.find(\',\');
    output= input.substr(index+1) +\" \" + input.substr(0,index);
    //display output string
    cout<<\"\ Converted string: \"<<output;
}

//main function
//pre-conditions: file exists and data is there,convert() in place
//postcondiitons:exits after readng file
int main()
{
    //declare variables
   string line;
   //open file for reading
ifstream myfile (\"names.txt\");
if (myfile.is_open())
{
      //read until EOF reached
    while ( getline (myfile,line) )
    {
        //pass each read line to funciton
      convert(line);
    }
    //close file after reading
    myfile.close();
}
//display err message if unable to open file
else cout << \"Unable to open file\";
   return 0;
}

Can someone help me with this code in C++? Write a function to convert a string containing lastName, firstName middleName to firstName middleName lastName. For
Can someone help me with this code in C++? Write a function to convert a string containing lastName, firstName middleName to firstName middleName lastName. For

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site