fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 10
  2. //
  3. /**************************************************************
  4.  * Name Formates
  5.  *
  6.  * ____________________________________________________________
  7.  *This program will format the entered names.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * User name
  11.  * OUTPUT
  12.  * formatted names.
  13.  **************************************************************/
  14. #include <iostream>
  15. #include <cstring>
  16.  
  17. using namespace std;
  18.  
  19. int main() {
  20. // Define arrays to store names
  21. const int SIZE = 50; // Maximum size for each name
  22. char firstName[SIZE];
  23. char middleName[SIZE];
  24. char lastName[SIZE];
  25. char fullName[3 * SIZE]; // Array to store the formatted full name
  26.  
  27. // Prompt user for their first, middle, and last names
  28. cout << "Enter your first name: ";
  29. cin.getline(firstName, SIZE);
  30.  
  31. cout << "Enter your middle name: ";
  32. cin.getline(middleName, SIZE);
  33.  
  34. cout << "Enter your last name: ";
  35. cin.getline(lastName, SIZE);
  36.  
  37. // Construct the formatted name
  38. strcpy(fullName, lastName); // Copy last name
  39. strcat(fullName, ", "); // Add a comma and space
  40. strcat(fullName, firstName); // Add first name
  41. strcat(fullName, " "); // Add a space
  42. strcat(fullName, middleName); // Add middle name
  43.  
  44. // Display the result
  45. cout << "Formatted name: " << fullName << endl;
  46. return 0;
  47. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty