Question: Write the function processName ( ). It's input is a full name in the form (First MI. Last). Your job is to use string member

 Write the function processName ( ). It's input is a fullname in the form (First MI. Last). Your job is to usestring member functions to break the name into the first name, last

Write the function processName ( ). It's input is a full name in the form (First MI. Last). Your job is to use string member functions to break the name into the first name, last name and middle initial, and return the processed name in the form "Last, First MI.". Use the string member functions substr(), find(), rfind(), find_first_not_of(), find_last_not_of() and at() to solve this problem. You may assume: that every name will have exactly one word for the first and last names and a single character, followed by a period for the middle initial. There will be at least one space separating each of the portions of the input name, but there may be more spaces. Complete the following file: main.cpp #include using namespace std; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 /** Processes a name containing First MI. Last. @param s the name formatted as described. @return the name processed to "Last, First MI." Include the quotes in the returned name. */ string processName(const string& s) { string result; // Process the name here Jint pos = s.find(" "); string first = s. substr(0, pos-1); int pos2 = s.find("."); string middle = s.substr(pos2-3, 4); int pos3 = s.rfind(" "); int pos4 = s.find_last_not_of("."); string last = s.substr(pos3+1, pos4-pos3); result = "" + last + ", " + first + middle +""; return result; } Submit Calling with Arguments Name Arguments Actual Expected pass process Name "Stephen D. Gilbert" "Gilbert, Stephen D." "Gilbert, Stephen D." fail processName "Francis X. Loyola" "Loyola, Franci X." "Loyola, Francis X." fail processName "Donald D. Duck ", Donal "Duck, Donald D." fail process Name Jeffry P. Palmister" "Palmister, Jeffry P. Palmister P." "Palmister, Jeffry P." fail process Name Jack N. Reacher Jack N. Reacher k N." "Reacher, Jack N." Score 1/5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To address the issue with handling multiple spaces we can process the string by manually using strin... View full answer

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 Databases Questions!