Question: C++ please. Ty. Write a function last_name_first that takes a string containing a name such as Harry Smith or Mary Jane Lee, and that returns

C++ please. Ty. C++ please. Ty. Write a function last_name_first that takes a string

Write a function last_name_first that takes a string containing a name such as "Harry Smith" or "Mary Jane Lee", and that returns the string with the last name first, such as "Smith, Harry" or "Lee, Mary Jane" Complete the following file: names.cpp 1 #include 2 using namespace std; 3 4 /** 5 Finds the last occurrence of target in the string str. 6 @param str the string to search 7 @param target the 1-character string to search for 8 @return the position of the last occurrence of target, or -1 if not found 9 */ 10 int find_last(string str, string target) 11 { 12 for (int i = str.length() - 1; i >= 0; i--) 13 { 14 if (str.substr(i, 1) == target) { return i; } 15 } 16 return -1; 17 } 18 19 /** 20 Changes a name so that the last name comes first. 21 @param name a name such as "Mary Jane Lee" 22 @return the reversed name, such as "Lee, Mary Jane". 23 If name has no spaces, it is returned without change. 24 25 string last_name_first(string name) 26 1 27 28 29 }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!