fork download
  1. //Cameron Pham CS1A Chapter 10, p. 589, #7
  2. //
  3. /*******************************************************************************
  4.  * ARRANGE FULL NAME
  5.  * ____________________________________________________________
  6.  *
  7.  * This program displays a person's name in the form "last, first middle",
  8.  * given the person's first, middle, and last names.
  9.  * ____________________________________________________________
  10.  * INPUTS
  11.  * firstName // Person's first name
  12.  * middleName // Person's middle name
  13.  * lastName // Person's last name
  14.  *
  15.  * OUTPUTS
  16.  * fullName // Name arranged as "last, first middle"
  17.  ******************************************************************************/
  18.  
  19. #include <iostream>
  20. #include <cstring>
  21. using namespace std;
  22.  
  23. int main()
  24. {
  25. const int NAME_SIZE = 30; // Size of each name array
  26. const int FULL_SIZE = 100; // Size of the arranged name array
  27. char firstName[NAME_SIZE] = ""; // First name
  28. char middleName[NAME_SIZE] = ""; // Middle name
  29. char lastName[NAME_SIZE] = ""; // Last name
  30. char fullName[FULL_SIZE] = ""; // Arranged name
  31. // Get the three names from the user
  32. cout << "Enter the first name: ";
  33. cin.getline(firstName, NAME_SIZE);
  34. cout << "Enter the middle name: ";
  35. cin.getline(middleName, NAME_SIZE);
  36. cout << "Enter the last name: ";
  37. cin.getline(lastName, NAME_SIZE);
  38. // Arrange the names as "last, first middle"
  39. strcpy(fullName, lastName);
  40. strcat(fullName, ", ");
  41. strcat(fullName, firstName);
  42. strcat(fullName, " ");
  43. strcat(fullName, middleName);
  44. // Display the arranged name
  45. cout << "\nArranged name: " << fullName << endl;
  46. return 0;
  47. }
Success #stdin #stdout 0s 544KB
stdin
John Bomboclatt Pork
stdout
Enter the first name: Enter the middle name: Enter the last name: 
Arranged name: , John Bomboclatt Pork