// Attached: Lab 2 - Program #2
// ===========================================================
// File: Lab2_Program2
// ===========================================================
// Programmer: Elaine Torrez
// Class: CMPR 121
// ===========================================================
#include <iostream>
#include <cstring> // for c-string functions
using namespace std;
// ==== main ====================================================
//
// This program uses c_strings (character arrays) to read a
// user's name and state, displays character counts, and
// compares the first and last names.
//
// =============================================================
int main()
{
// Variable declarations (empty c-strings)
char firstName[20] = "";
char lastName[20] = "";
char fullName[40] = "";
char city[30] = "";
// Input
cout << "Enter your first name: ";
cin.getline(firstName, 20);
cout << "Enter your last name: ";
cin.getline(lastName, 20);
cout << "Enter the state you live in: ";
cin.getline(city, 30);
// Processing
strcpy(fullName, firstName);
strcat(fullName, " ");
strcat(fullName, lastName);
// Output
cout << "Hi " << fullName << ". So you live in " << city << "." << endl;
cout << "Your first name has " << strlen(firstName)
<< " characters," << endl;
cout << "and your last name has " << strlen(lastName)
<< " characters." << endl;
if (strcmp(firstName, lastName) == 0)
{
cout << "Your first and last names are the same." << endl;
}
else
{
cout << "Your first and last names are different." << endl;
}
cout << "Press any key to continue . . .";
cin.get();
return 0;
} // end of main()
// =============================================================