1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include<iostream>
// #include<cstring>
#include<string>
// using namespace std;
int main()
{
//Declare/initialize variables/arrays
// const int MAX_SIZE = 100;
// char firstName[MAX_SIZE];
// char lastName[MAX_SIZE];
// char middleName[MAX_SIZE];
std::string firstName ;
std::string lastName ;
std::string middleName ;
// char combinedNames[MAX_SIZE];
// char comma[] = { ',' };
// char space[] = { ' ' };
// char nullTerminator[] = { '\n' };
const char comma = ',' ;
const char space = ' ' ;
std::cout << "This program will ask for your first , last and middle names.\n" ; // << endl;
std::cout << "Then it will properly arrange them as follows last, first and middle.\n\n" ; // << endl << endl;
//get input from user
std::cout << "Please enter your first name :";
//cin.getline(firstName, MAX_SIZE);
std::cin >> firstName ;
//cout << endl;
std::cout << "\nPlease enter your last name :";
// cin.getline(lastName, MAX_SIZE);
std::cin >> lastName ;
// cout << endl;
std::cout << "\nPlease enter your middle name :";
// cin.getline(middleName, MAX_SIZE);
std::cin >> middleName ;
// cout << endl;
//combine all names
/*
strncpy_s(combinedNames, lastName,strlen(lastName));
strncpy_s(combinedNames, comma,strlen(comma));
strncpy_s(combinedNames, space,strlen(space));
strncpy_s(combinedNames, firstName,strlen(firstName));
strncpy_s(combinedNames, space,strlen(space));
strncpy_s(combinedNames, middleName,strlen(middleName));
strncpy_s(combinedNames, nullTerminator, strlen(nullTerminator));
*/
const std::string combinedName = lastName + comma + space + firstName + space + middleName ;
std::cout << '\n' << combinedName << '\n' ; // endl;
// system("pause");
// return 0;
}
|