//----------------------------------------------------------------------------
//----Write a program that reads in a list of people's names and ages,
//----and writes them out in alphabetical order by name.
//----------------------------------------------------------------------------
#include <iostream.h>
#include <stdlib.h>
#include "stringclass.h"

void ReadNameAge(char* WhichPerson, string& FirstName, string& LastName,
int& Age);
void MakeFullName(string& FirstName, string& LastName);
//----------------------------------------------------------------------------
int main(void) {

string FirstName1,
    FirstName2,
    LastName1,
    LastName2,
    TempString;
int Age1,
    Age2,
    TempInt;

//----Prompt user for names and ages, and read
ReadNameAge("first",FirstName1,LastName1,Age1);
ReadNameAge("second",FirstName2,LastName2,Age2);

//----If possible join names into one string, else copy last name to first
MakeFullName(FirstName1,LastName1);
MakeFullName(FirstName2,LastName2);

//----Compare last names and swap if out of order
if (LastName1 > LastName2) {
    TempString = FirstName1;
    FirstName1 = FirstName2;
    FirstName2 = TempString;
    TempInt = Age1;
    Age1 = Age2;
    Age2 = TempInt;
    }

//----Output the names and ages
cout << "In alphabetical order by last name they are:" << endl;
cout << FirstName1 << " " << Age1 << endl;
cout << FirstName2 << " " << Age2 << endl;

//----End program
return(0);
}
//----------------------------------------------------------------------------
//----Prompt user for names and ages, and read
void ReadNameAge(char* WhichPerson, string& FirstName, string& LastName,
int& Age) {

cout << "Enter the first and last names and age for the " << WhichPerson
     << " person:" << endl;
cin >> FirstName >> LastName >> Age;
}
//----------------------------------------------------------------------------
void MakeFullName(string& FirstName, string& LastName) {

FirstName += " ";
FirstName += LastName;
}
//----------------------------------------------------------------------------
