*I don't know how to use peek or putback! (no loops allowed)
Write a C++ program that prompts the user to enter their full name (first name, middle name or middle initial and then last name) each separated by a whitespace.
Your program will then output their name, as well as their initials, to the standard output screen.
Your program MUST utilize the following member functions for the cin object:
peek, get, putback and ignore. You may use these functions more than once BUT YOU MUST USE ALL OF THEM AT LEAST ONCE.
Your program is NOT allowed to have more than the following six variable declaration types:
-‐three variables of type string to store the three name parts
-‐three variables of type char to store the initials
Call your source file Initials.cpp
If the input was: John W Frank
The output would be: Your name is John W Frank Your initials are JWF
Look at the example codes, they usually give a general idea of what they do. Why don't you start programming something and if you run into a problem post the code along with a question and someone will try to help.
Are you sure no loops are allowed ? These member functions (for this task anyways) would be optimally used in a loop, I can't see them not being used in at least one loop.
Cout << “Please enter your full name.” << endl;
Cin >> firstname >> middleName >> lastName;
Cout << “Your full name is “ <<firstName << middleName << lastName << endl;
Cout<< “Your initials are” << ch1 << ch2 << ch3 << endl;
The problem is that I can't figure out how to use peek or putback. Also, I can't figure out how to make it get the first character of each word and the entire word for outputting the entire name. For example, if I type in John A Doe, it will give me JAD but it can't tell me that the name is John A Doe.
char fInitial, mInitial, lInitial;
string fName, mName, lName;
cout << "Enter your name" << endl;
// get all chars until a whitespace delimiter is found
// if they only entered one name this will hang
getline(cin, fName, ' ');
fInitial = fName;
// same as above
// if they only entered two names this will hang
getline(cin, mName, ' ');
mInitial = mName;
// gets all chars until a newline is found because it's
// supposed to be the last word and so unless they actually
// press the spacebar at the end a whitepace will not show up
getline(cin, lName, '\n');
lInitial = lName;
cout << "Your name is " << fName << " " << mName << " " << lName
<< " your initals are " << fInitial << mInitial << lInitial << endl;