fork download
  1.  
  2. //Dione Torrevillas CS1A Chapter 10, P. 589, #7
  3. /******************************************************************************
  4.  * NAME ARRANGER
  5.  * This program accepts the user's first, middle, and last
  6.  * names and arranges them with the last name appearing first.
  7.  *
  8.  * INPUT:
  9.  * firstName : User's first name
  10.  * middleName : User's middle name
  11.  * lastName : User's last name
  12.  *
  13.  * OUTPUT:
  14.  * fullName : Arranged full name
  15.  ******************************************************************************/
  16. #include <iostream>
  17. #include <cstring>
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22. const int SIZE = 50;
  23. char firstName[SIZE];
  24. char middleName[SIZE];
  25. char lastName[SIZE];
  26. char fullName[160];
  27.  
  28. // Get the first, middle, and last names.
  29. cout << "Enter your first name: ";
  30. cin.getline(firstName, SIZE);
  31.  
  32. cout << "Enter your middle name: ";
  33. cin.getline(middleName, SIZE);
  34.  
  35. cout << "Enter your last name: ";
  36. cin.getline(lastName, SIZE);
  37.  
  38. // Arrange the names in the fourth array.
  39. strcpy(fullName, lastName);
  40. strcat(fullName, ", ");
  41. strcat(fullName, firstName);
  42. strcat(fullName, " ");
  43. strcat(fullName, middleName);
  44.  
  45. // Display the arranged name.
  46. cout << "Arranged name: " << fullName << endl;
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 544KB
stdin
Carol 
Lynn 
Smith
stdout
Enter your first name: Enter your middle name: Enter your last name: Arranged name: Smith, Carol  Lynn