In C Write a program that allows the user to enter any numbe

In C# Write a program that allows the user to enter any number of names. Your prompt can inform the user to input their first name followed by a space and last name. Order the names in ascending order and display the results with the last name listed first, followed by a comma and then the first name. If a middle initial is entered, it should follow the first name. Your solution should also take into consideration that some users may only enter their last name (one name).

Solution

#include #include using namespace std; // An easiest way to declare the whole namespaces int main() { string myString, last, first, middle; cout << \"Enter your name: First, Middle Last\" << endl; getline(cin, myString); // used to include spaces in the strings char comma, space1, space2; comma = myString.find_first_of(\',\'); space1 = myString.find_first_of(\' \'); space2 = myString.find_last_of(\' \'); last = myString.substr (0, comma); // user input last name first = myString.substr (space1+1, space2 - space1); // user input first name middle = myString.substr (space2+1, -1); // user input middle name middle.erase(1, -1); // erases full middle name, only leaving the first character as initial cout << last << \" \" << middle << \". \" << first << endl;//displays output return 0; }
In C# Write a program that allows the user to enter any number of names. Your prompt can inform the user to input their first name followed by a space and last

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site