1. Write a function that prompts the user to enter his or her first name and last name, as two separate
values. This function should return both values to the caller via additional pointer (or reference)
parameters that are passed to the function. Try doing this first with pointers and then with references.
(Hint: the function signature will look similar to the swap function from earlier!)
3. Modify the program you wrote for exercise 1 so that instead of always prompting the user for a last
name, it does so only if the caller passes in a
NULL pointer for the last name.
My answer for question 1:
Code:
#include <iostream>
#include <string>
using namespace std;
void get_name(string *first_name, string *last_name)
{
std::cout << "First name: ";
std::getline(cin,*first_name);
std::cout <<endl;
std::cout << "Last name: ";
std::getline(cin,*last_name);
std::cout << endl;
}
int main()
{
string first_name, last_name;
get_name(&first_name,&last_name);
std::cout << "Hello " << first_name << " " << last_name << endl;
return 0;
}
I'm not really sure what the question want me to do, or what is the purpose in it.