1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
{
char first, middlename, lastname, c,count;
count = 0;
cout << "Please enter your first, middle, and last names: ";
getline(cin,fullname);
cout << "\n";
while ((fullname.empty()) || (fullname == " "))
{
cout << "Please enter your first, middle, and last names: ";
getline(cin, fullname);
cout << "\n";
}
for (int i = 0; i < fullname.length(); i++)
{
c = fullname.at(i);
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == ' ')))
{
cout << "Please enter your first, middle, and last names: ";
getline(cin, fullname);
}
}
first = fullname.find(" ", 0) - 1;
middlename = first + 1;
while (isspace(fullname[middlename]))middlename++; count++;
lastname = fullname.find(" ", middlename);
while (isspace(fullname[lastname]))lastname++;
cout << "Your Name" << " " << "Your name written proffessionally" << endl;
cout << fullname.substr(0, first + 1) + " " + fullname.substr(middlename, ( first+ count)) + " " + fullname.substr(lastname, fullname.length() - lastname) +
" " + fullname.substr(lastname, fullname.length() - lastname) + ", " + fullname.substr(0, first + 1) + ", " + fullname.substr(middlename, 1) + ".\n" << endl;
return(fullname);
}
|