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

Main Method 1. Declare a string called myString. 2. Use Call-by-reference pass y

ID: 3626907 • Letter: M

Question

Main Method
1. Declare a string called myString.
2. Use Call-by-reference pass your string to a method called inputData(); (Hint: uses the &)
3. Use Call-by-value and pass your string to a method called outputData(); (Hint: does not use the &)
inputData Method (Receives string)
1. Get input using cin >> into the string variable you received into this method. (I will be entering my full name in the format of: Last, First Middle.
2. Using the string methods mentioned in this weeks lecture, have your program change the string to: First Middle Initial Last.
3. I would like you to break the string you received apart into 3 separate variables: first, last, middle. (Hint: use find() to find the "," and spaces and use substr() to extract the pieces)
4. Use string concatenation to reassemble the string and overwrite the string you received with the new value.
5. You must use each of the following string methods (at least once): substr(), length(), find(), insert(), erase().
6. Notice the "," is missing out of the name.
outputData Method (Receives string)
1. Output the new string to the screen using cout <<.
2. Comments are required, but pseudocode or flowchart are not.
3. All Input/Output should be done using the standard C++ library string class.
4. Include: system("PAUSE"); after your output to pause the screen.
Ensure you include ALL files required to make your program compile and run. I would like to see your .cpp file and the .exe file that is inside your debug directory.
[code]
#include <iostream>
#include <string>

using namespace std;
void inputData(string& first, string& middle, string& last)
{
first.substring();
middle.erase(2);
last.substring();
}

int main()
{
string myString;

cout << "Please enter your Last, First Middle Name" << endl;
cout << endl;
cout << endl;

getline(cin, myString);

int comma = myString.find (","); // use this to make sure comma is equal to reversecomma since there can only be one comma
int reversecomma = myString.rfind(","); //to compare with comma
int totalName = myString.length(); // get the over all lenght
int firstSpace = myString.find(' '); // this finds the first space I was using rfind to find the second but found if there
int secondSpace = myString.find(' ', firstSpace + 1);// is a third white-space it still would include it when finding.
int thirdSpace = myString.find(' ', secondSpace + 1); // this is to test if when inputted someone hits the spacebar afterwords


while ((comma != reversecomma) || ((reversecomma + 2)>= secondSpace) || (firstSpace == 0) || (thirdSpace != -1))
{//Here I begin testing inputs to see if accurate notice comma has to equal reversecomma if not starts loop then I use
//reversecomma which measures from the end to beginning and add 2 to the int which is how many spaces it should include
// firstSpace happens if someone puts a space before last name
// finally thirdSpace is to test to see if there is any spaces after Middle name.
cout << "You need to have a comma in between Last and First name only" << endl;
cout << "For example Doe, John Ericson or you may have to many white-spaces" << endl;
cout << "Please try again enter Last, First Middle Name" << endl;
getline(cin, myString);


comma = myString.find (",");
reversecomma =myString.rfind(",");
totalName = myString.length();
firstSpace = myString.find(' ');
secondSpace = myString.find(' ' , firstSpace + 1);
thirdSpace = myString.find(' ', secondSpace + 1);
}
// now that it as gone through the checks to make sure information is accurate I can begin setting up container so I will need
// prototype this is located before Main();

string c = myString.substr(0, comma);
c.insert(0, " ");

string a = myString.substr(firstSpace , (secondSpace - firstSpace));


string b = myString.substr(secondSpace + 1, (totalName - secondSpace)+ 1);
b.insert(0, " ");

cout << a << b << c << endl;
inputData(a, b, c);



cout << endl;
cout << endl;

system("PAUSE") ;
return EXIT_SUCCESS;
}

Explanation / Answer

hi there here is the program fixed the way u want #include #include #include using namespace std; //call by reference void inputData(string& myString) { cout
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