Question: If necessary, create a new project named TryThis16 Project and save it in the Cpp8Chap13 folder. Enter the C++ instructions from Figure 13-15 into a
If necessary, create a new project named TryThis16 Project and save it in the Cpp8\Chap13 folder. Enter the C++ instructions from Figure 13-15 into a source file named TryThis16.cpp. Change the filename in the first comment to TryThis16.cpp. Save and then run the program. Test the program using the data shown in Figure 13-15 in the chapter. Now, modify the program so the user enters the last name followed by a comma, a space, and the first name. The program should display the first name followed by a space and the last name. Be sure to modify the comments that document the program’s purpose. Save and then run the program. Test the program appropriately.
Figure 13-15

1 //Rearrange Name.cpp - displays the last name 2 //followed by a comma, a space, and the first name 3 //Created/revised by on 4 5 #include 6 #include 7 using namespace std; 9 int main() 10 { string firstlast = string first = ""; string last = ""; int spacelocation 11 12 13 %3D 14 0; %3D 15 16 //get first and last name cout "Name (first and last only): "; getline (cin, firstlast); 17 18 19 //locate space, then pull out first and last names spacelocation = firstLast.find (" ", 0); first = firstlast. substr (0, spacelocation); last = firstlast.substr(spaceLocation + 1); 20 21 22 23 24 //display rearranged name cout last
Step by Step Solution
3.32 Rating (167 Votes )
There are 3 Steps involved in it
TryThis16cpp displays the first name followed by a spa... View full answer
Get step-by-step solutions from verified subject matter experts
