Last_Name, First_Name Middle_Initial. For example, the input Mary Average User s
ID: 3618141 • Letter: L
Question
Last_Name, First_Name Middle_Initial.
For example, the input
Mary Average User
should produce the output:
User, Mary A.
The input
Mary A. User
should also produce the output:
User, Mary A.
Your program should work the same and place a period after themiddle initial even if the input did not contain a period. Yourprogram should also allow for users who give no middle name ormiddle initial. In that case, the output, of course, contains nomiddle name or initial. For example, the input
Mary User
should produce the output
User, Mary
If you are using C strings, assume that each name is at most 20characters long. Alternatively, use the class string.(Hint:You may want to use three string variables ratherthan one large string variable for the input. You may find iteasier to notuse getline.)
Here is what i have:
#include <iostream>
#include <string>
using namespace std;
// ====================
// main function
// ====================
int main()
{
//
// Variable declarations
//
string first, second, third; // strings read in
char ch; // character in input after secondstring
char middleInitial;
//
// Get the first two strings read in (first andmiddle names or
// first and last names)
cout << endl;
cout << "Enter your name (first middle last):";
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
// --------------------------------
// --------- END USER CODE --------
// --------------------------------
return 0;
}
Explanation / Answer
please rate - thanks #include using namespace std; int main() {char last[20],first[15],middle[15],firstkt,middlekt,lastkt; string name; int j,i; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.