Answer to Question #315523 in C++ for nickname

Question #315523

Int's are not the only data type that can be passed to a function. All valid data types, such as double, char, bool, string, etc. can be passed.

 

Ask the user to enter their first name and last name in main(). Pass those values to a function and produce the last two lines of output shown below:

 

Output:

Enter your first name:   [user types: Mary Jo]

Enter your last name:    [user types: De Arazoza]

Your full name is: Mary Jo De Arazoza

Your name can also be written as: De Arazoza, Mary Jo



1
Expert's answer
2022-03-23T02:58:09-0400
#include <iostream>
#include <string>
using namespace std;

void function(string first, string last) {
    string full = first + " " + last;
    cout << "Your full name is: " << full << endl;

    full = last + ", " + first;
    cout << "Your name can also be written as: " << full << endl;
}


int main() {
    string first, last;

    cout << "Enter your first name: ";
    getline(cin, first);

    cout << "Enter yor last name: ";
    getline(cin, last);

    function(first, last);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog