fork download
  1. // Saliha Babar CS1A Chapter 10, #7, Page 589
  2. //
  3. /*****************************************************************************
  4.  * NAME ARRANGER
  5.  * ___________________________________________________________________________
  6.  * This program accepts first, middle and last name, then it will arrange the
  7.  * full name based on certain formatting.
  8.  *
  9.  * Formatting of full name is as following
  10.  * Last, First Middle
  11.  * ___________________________________________________________________________
  12.  * INPUT
  13.  * SIZE : size of each strings
  14.  * firstName : first name
  15.  * middleName : middle name
  16.  * lastName : last name
  17.  *
  18.  * OUTPUT
  19.  * fullName : full name based on formatting
  20.  * ***************************************************************************/
  21.  
  22. #include <iostream>
  23. #include <cstring>
  24. using namespace std;
  25.  
  26. int main() {
  27. const int SIZE = 16; // INPUT - size of strings
  28. char firstName[SIZE]; // INPUT - first name
  29. char middleName[SIZE]; // INPUT - middle name
  30. char lastName [SIZE]; // INPUT - last name
  31. char fullName[(SIZE *3) + 3] = ""; // OUTPUT - full name
  32.  
  33. cout << "Enter your first name up to " << SIZE -1 << " characters.\n";
  34. cin.getline (firstName, SIZE);
  35.  
  36. cout << "Enter your middle name up to " << SIZE -1 << " characters.\n";
  37. cin.getline (middleName, SIZE);
  38.  
  39. cout << "Enter your last name up to " << SIZE -1 << " characters.\n";
  40. cin.getline (lastName, SIZE);
  41.  
  42. // Adjust the strings by sequence
  43. // Last name followed by comma, and space
  44. strcat (fullName, lastName);
  45. strcat (fullName, ", ");
  46.  
  47. // Followed by first name, space and middlename
  48. strcat (fullName, firstName);
  49. strcat (fullName, " ");
  50. strcat (fullName, middleName);
  51.  
  52. cout <<"\nHere is your full name : " << fullName << endl;
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0s 5268KB
stdin
Nur
Alia
Natasha
stdout
Enter your first name up to 15 characters.
Enter your middle name up to 15 characters.
Enter your last name up to 15 characters.

Here is your full name : Natasha, Nur Alia