Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

What is cost plus pricing ?

Answered: 1 week ago

Question

1. What are the types of wastes that reach water bodies ?

Answered: 1 week ago

Question

Which type of soil has more ability to absorb water?

Answered: 1 week ago