I'm having trouble trying to figure out how to list these names with the first name first and the last name second without the comma. Hopefully someone can help me with this one! Any help will be greatly appreciated. Thanks, Zeni3773
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void getdata();
void sortThem();
void swapThem();
void showIt();
char lname[25][35],fname[25][35];
int i=-1,j,num;
string Lname[25],Fname[25];
void main()
{
getdata();
sortThem();
showIt();
}
void getdata()
{
ifstream x;
x.open("namesid.txt");
while(!x.eof())
{
i++;
x>>Lname[i];x>>Fname[i];
cout<<Lname[i]<<" "<<Fname[i]<<endl;
}
num = i+1;
}
void sortThem()
{
cout<<endl<<endl;
for(i=0; i<=num; i++)
{
for(j=i; j<=num; j++)
{
if(Lname[i]>Lname[j])
swapThem();
}
}
}
void swapThem()
{
string temp;
temp = Lname[j];
Lname[j] = Lname[i];
Lname[i] = temp;
temp = Fname[j];
Fname[j] = Fname[i];
Fname[i] = temp;
}
void showIt()
{
cout<<endl<<endl;
for(i=0; i<=num; i++)
cout<<Lname[i]<<" "<<Fname[i]<<endl;
}
Tagged by Salem