fork download
  1. //Andrew Alspaugh CS1A Chapter 10. P. 589. #7.
  2. //
  3. /****************************************************************************
  4. Create Full Name
  5. ___________________________________________________________________________
  6. This program displays a full name:
  7. last, first middle
  8. ____________________________________________________________________________
  9. //Input
  10.   const int SIZE = 16;
  11.  
  12.   char first[SIZE];
  13.   char middle[SIZE];
  14.   char last[SIZE];
  15.  
  16. //Output
  17. int sizeFULL;
  18. ****************************************************************************/
  19. #include <iostream>
  20. #include <cstring>
  21. using namespace std;
  22.  
  23. void BuildFullName(const char* first, const char* middle, const char* last, char* fullName, int fullSize);
  24.  
  25. int main()
  26. {
  27. //DATA DICTIONARY
  28. //Input
  29. const int SIZE = 16;
  30.  
  31. char first[SIZE];
  32. char middle[SIZE];
  33. char last[SIZE];
  34.  
  35. //Output
  36. int sizeFULL;
  37.  
  38. // INPUT
  39. cin.getline(first, SIZE);
  40. cin.getline(middle, SIZE);
  41. cin.getline(last, SIZE);
  42.  
  43. // PROCESS
  44. sizeFULL = strlen(first) + strlen(middle) + strlen(last) + 4;
  45. char *Name = new char[sizeFULL];
  46.  
  47. BuildFullName(first, middle, last, Name, sizeFULL);
  48.  
  49. // OUTPUT
  50. cout << Name << endl;
  51.  
  52. delete [] Name;
  53.  
  54. return 0;
  55. }
  56.  
  57. void BuildFullName(const char* first, const char* middle, const char* last, char* fullName, int fullSize)
  58. {
  59. strcpy(fullName, last);
  60. strcat(fullName, ", ");
  61. strcat(fullName, first);
  62. strcat(fullName, " ");
  63. strcat(fullName, middle);
  64. }
Success #stdin #stdout 0.01s 5284KB
stdin
Walter
Hartwell
White
stdout
White, Walter Hartwell