<em>Complete Question:</em>
<em>Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. </em>
<em>Example output if the input is: Maya Jones
</em>
<em>Jones, Maya</em>
<em></em>
<em>In C++</em>
<em></em>
Answer:
The program written in C++ is as follows
<em>#include<iostream></em>
<em>using namespace std;</em>
<em>int main(){</em>
<em>string lname, fname;</em>
<em>cout<<"First name: ";</em>
<em>cin>>fname;</em>
<em>cout<<"Last name: ";</em>
<em>cin>>lname;</em>
<em>cout<<lname<<", "<<fname;</em>
<em>return 0;</em>
<em>}</em>
<em />
Explanation:
This line declares lname, fname as string to get the user's last name and first name, respectively
<em>string lname, fname;</em>
This line prompts the user for first name
<em>cout<<"First name: ";</em>
This line gets the user first name
<em>cin>>fname;</em>
This line prompts the user for last name
<em>cout<<"Last name: ";</em>
This line gets the user last name
<em>cin>>lname;</em>
This line prints the desired output
<em>cout<<lname<<", "<<fname;</em>