// Saliha Babar CS1A Chapter 10, #7, Page 589
//
/*****************************************************************************
* NAME ARRANGER
* ___________________________________________________________________________
* This program accepts first, middle and last name, then it will arrange the
* full name based on certain formatting.
*
* Formatting of full name is as following
* Last, First Middle
* ___________________________________________________________________________
* INPUT
* SIZE : size of each strings
* firstName : first name
* middleName : middle name
* lastName : last name
*
* OUTPUT
* fullName : full name based on formatting
* ***************************************************************************/
#include <iostream>
#include <cstring>
using namespace std;
int main( ) {
const int SIZE = 16 ; // INPUT - size of strings
char firstName[ SIZE] ; // INPUT - first name
char middleName[ SIZE] ; // INPUT - middle name
char lastName [ SIZE] ; // INPUT - last name
char fullName[ ( SIZE * 3 ) + 3 ] = "" ; // OUTPUT - full name
cout << "Enter your first name up to " << SIZE - 1 << " characters.\n " ;
cin .getline ( firstName, SIZE) ;
cout << "Enter your middle name up to " << SIZE - 1 << " characters.\n " ;
cin .getline ( middleName, SIZE) ;
cout << "Enter your last name up to " << SIZE - 1 << " characters.\n " ;
cin .getline ( lastName, SIZE) ;
// Adjust the strings by sequence
// Last name followed by comma, and space
strcat ( fullName, lastName) ;
strcat ( fullName, ", " ) ;
// Followed by first name, space and middlename
strcat ( fullName, firstName) ;
strcat ( fullName, " " ) ;
strcat ( fullName, middleName) ;
cout << "\n Here is your full name : " << fullName << endl;
return 0 ;
}
Ly8gU2FsaWhhIEJhYmFyICAgICAgICAgICAgICAgICAgQ1MxQSAgICAgICAgICAgICAgICAgQ2hhcHRlciAxMCwgIzcsIFBhZ2UgNTg5Ci8vCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKiBOQU1FIEFSUkFOR0VSCiAqIF9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwogKiBUaGlzIHByb2dyYW0gYWNjZXB0cyBmaXJzdCwgbWlkZGxlIGFuZCBsYXN0IG5hbWUsIHRoZW4gaXQgd2lsbCBhcnJhbmdlIHRoZSAKICogZnVsbCBuYW1lIGJhc2VkIG9uIGNlcnRhaW4gZm9ybWF0dGluZy4KICogCiAqIEZvcm1hdHRpbmcgb2YgZnVsbCBuYW1lIGlzIGFzIGZvbGxvd2luZwogKiBMYXN0LCBGaXJzdCBNaWRkbGUKICogX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCiAqIElOUFVUCiAqICAgU0laRSAgICAgICA6IHNpemUgb2YgZWFjaCBzdHJpbmdzCiAqICAgZmlyc3ROYW1lICA6IGZpcnN0IG5hbWUKICogICBtaWRkbGVOYW1lIDogbWlkZGxlIG5hbWUKICogICBsYXN0TmFtZSAgIDogbGFzdCBuYW1lCiAqIAogKiBPVVRQVVQKICogICBmdWxsTmFtZSAgIDogZnVsbCBuYW1lIGJhc2VkIG9uIGZvcm1hdHRpbmcKICogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJY29uc3QgaW50IFNJWkUgPSAxNjsgICAgICAgIC8vIElOUFVUIC0gc2l6ZSBvZiBzdHJpbmdzCgljaGFyIGZpcnN0TmFtZVtTSVpFXTsgICAgICAgLy8gSU5QVVQgLSBmaXJzdCBuYW1lCgljaGFyIG1pZGRsZU5hbWVbU0laRV07ICAgICAgLy8gSU5QVVQgLSBtaWRkbGUgbmFtZQoJY2hhciBsYXN0TmFtZSBbU0laRV07ICAgICAgIC8vIElOUFVUIC0gbGFzdCBuYW1lCgljaGFyIGZ1bGxOYW1lWyhTSVpFICozKSArIDNdID0gIiI7IC8vIE9VVFBVVCAtIGZ1bGwgbmFtZQoKCWNv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