alphebitizing a list

I have to do a program for my class that involves reading in a list from a file and alphabetizing the names. I have written the code except for the alphebetizing part. can anyone help me or give me some pointers?

#include <iostream>
#include <fstream>
using namespace std;
/////////////////////////////////
class agent
{
protected:
char name[20];
char nick[20];
char snack[20];
int num;
int num2;
public:
void getData()
{
cout <<"\nEnter the agents number: "; cin >> num;
cout <<"\nEnter the agents first name: "; cin >> name;
cout <<"\nEnter the agents nickname: "; cin >> nick;
cout <<"\nEnter the agents favorite midnight snack: "; cin >> snack;
}
void showData()
{
num2 = (num+7777)%10;
cout <<"\nNumber: "<<num1;
cout <<"\nName: "<<name;
cout <<"\nNickname: "<<nick;
cout <<"\nFavorite midnight snack: "<<snack;
}
};
/////////////////////////////////
int main()
{
char ch;
agent agnt;
fstream file;

file.open("agents.list", ios::app | ios::out | ios::in |ios::binary );

do
{
cout <<"\nEnter agents data:";
agnt.getData();

file.write( reinterpret_cast<char*>(&agnt), sizeof(agnt));
cout <<"Enter another agent?(y/n)";
cin >>ch;
}while(ch=='y');
file.seekg(0);

file.read( reinterpret_cast<char*>(&agnt), sizeof(agnt));
while( !file.eof())
{cout<<"\nAgent:";
agnt.showData();
file.read( reinterpret_cast<char*>(&agnt), sizeof(agnt));
}
cout<<endl;
return 0;
}
Hmmm you could do it this way: use the ASCII numerical values of each letter as a guide to put them into an order of lowest to highest. You should be able to use std::sort included in <algorithm> (although not tested). However, someone will point at that this is basing the entire program on the fact that the computer running this program is using ASCII.

I'll be interested to see some of the suggestions put forward.
Topic archived. No new replies allowed.