Write a program that reads a person's first and last names separated by a space, assuming the first and last names are both single words. Then the program outputs last name, first name. End with newline.

Respuesta :

Below is the program written in C++ that reads a person's first and last names separated by a space, assuming the first and last names are both single words.

Coding Part:

#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 of all the steps:

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;

To know more about C++ Programming, visit: https://brainly.com/question/13441075

#SPJ4