fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 10 P.359 #7
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Name Arranger
  6.  * ____________________________________________________________________________
  7.  * This program will accept the users first, middle, and last name and then
  8.  * rearrange the names and display them as "last, first middle".
  9.  * ____________________________________________________________________________
  10.  * Input
  11.  * SIZE :Character limit
  12.  * first :first name
  13.  * middle :middle name
  14.  * last :last name
  15.  * Output
  16.  * fullName :formatted full name the user enterred
  17.  *****************************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <cstring>
  21. using namespace std;
  22.  
  23. int main() {
  24. //Data Dictionary
  25. const int SIZE = 50;
  26. char first[SIZE];
  27. char middle[SIZE];
  28. char last[SIZE];
  29. char fullName[SIZE * 3];
  30.  
  31. //User Input
  32. cout << "Enter your first name: " << endl;
  33. cin.getline(first, SIZE);
  34. cout << "Enter your middle name: " << endl;
  35. cin.getline(middle, SIZE);
  36. cout << "Enter your last name: " << endl;
  37. cin.getline(last, SIZE);
  38.  
  39. //Compute Display
  40. strcpy(fullName, last);
  41. strcat(fullName, ", ");
  42. strcat(fullName, first);
  43. strcat(fullName, " ");
  44. strcat(fullName, middle);
  45.  
  46. cout << "Formatted name: " << fullName << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5320KB
stdin
lebron
raymone
james
stdout
Enter your first name: 
Enter your middle name: 
Enter your last name: 
Formatted name: james, lebron raymone