cout << " 1. Sort names by surnames then first names "<<endl;
cout << " 2. Sort names by first names then by surnames "<<endl;
cout<< "Enter your sorting choice: " ;
cin >> choice;
if (choice == 1)
{
cout<< "The names are sorted by surnames then first names"<<endl;
sortSurnameFirst (surnames, names,count);
displayNames(surnames, names,count);
}
if (choice == 2)
{
cout<< "The names are sorted by first names then surnames"<<endl;
sortSurnameFirst (surnames, names,count);
displayNames(surnames, names,count);
}
}
else
{
cout << "The following file doesnt exist" << endl;
}
return 0;
}
void sortSurnameFirst (string surnames[], string names[], size_t size)
{
bool swap;
string sort ;
string temp;
do
{
swap = false;
for (size_t i =0; i < size ; i++)
{
if (surnames[i] > surnames[i++])
{
sort = surnames[i];
surnames[i] = surnames[i++];
surnames[i++] = sort ;
swap = true;
[CODE]
Name Sorting
-----------------------------------------------------
Enter the file name: names.txt
1. Sort names by surnames then first names
2. Sort names by first names then surnames
Enter your sorting choice: 1
-----------------------------------------------------
Surname First Name
-----------------------------------------------------
Adams Grace
Adams Hein
Adams Samantha
Babajide Pretty
chadwick billy
deWet Abel
Olivier Vreda
Venter Charlie
Name Sorting
-----------------------------------------------------
Enter the file name: names.txt
1. Sort names by surnames then first names
2. Sort names by first names then surnames
Enter your sorting choice: 2
-----------------------------------------------------
Surname First Name
-----------------------------------------------------
deWet Abel
chadwick billy
Venter Charlie
Adams Grace
Adams Hein
4
Babajide Pretty
Adams Samantha
[CODE/]