Respuesta :
Complete Question:
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.
Example output if the input is: Maya Jones
Jones, Maya
In C++
Answer:
The program written in C++ is as follows
#include<iostream>
using namespace std;
int main(){
string lname, fname;
cout<<"First name: ";
cin>>fname;
cout<<"Last name: ";
cin>>lname;
cout<<lname<<", "<<fname;
return 0;
}
Explanation:
This line declares lname, fname as string to get the user's last name and first name, respectively
string lname, fname;
This line prompts the user for first name
cout<<"First name: ";
This line gets the user first name
cin>>fname;
This line prompts the user for last name
cout<<"Last name: ";
This line gets the user last name
cin>>lname;
This line prints the desired output
cout<<lname<<", "<<fname;
The program in Python is
person_name = input("Enter your first name and last name separated
by space: ")
split_names = person_name.split( )
first_name = split_names[0]
last_name = split_names[1]
print(last_name + ", " + first_name)
The first line of the program requests the first and last names as a single string, separated by a space.
The next line splits the name into first and last names
Finally, the print statement displays the names reversed, but separated with a comma
See another example of a Python program here: https://brainly.com/question/21861447