Here i have a program that reads a file of employee data into an array of structs. I have a function that searches the array and finds the oldest person and prints out that person's data. But now i need to modify a function that sorts through the array and moves the oldest persons data to the 1st position in the array, the 2nd oldest to the 2nd position and so on and does the same for all 1000 employees so that it will sort then print all employee data from oldest to youngest. How could i do this?
Here is the first few lines of data to give an idea of the layout(date of birth is laid out YYYYMMDD
114680858 19670607 Matilda Vincent MI
114930037 19471024 Desdemona Hanover ID
115550206 19790110 Xanadu Perlman ND
116520629 19630921 Alexander Hall SD
struct employees // employee data
{
int ss_number;//social security
int dob;//date of birth YYYY/MM/DD Ex.) 19870314=1987/03/14
string f_name;
string l_name;
string state; //state of residence
};
void read_file()//read file into array of 1000 structs
{
ifstream data("/home/www/class/een118/labs/database1.txt");
employees array[1000]
if(!data.fail())
{
int i;
for(int i=0;i<1000;i++)
{
data>>array[i].ss_number
>>array[i].dob
>>array[i].f_name
>>array[i].l_name
>>array[i].state;
}
for(int i=0;i<1000;i++)
{
cout<<array[i].ss_number>>" "<<array[i].dob>>" "<<array[i].f_name>>" "<<
array[i].l_name>>" "<<array[i].state;
}}}
void print_person(employees e)
{
cout<<e.ss_number>>" "<<e.dob>>" "<<e.f_name>>" "<<e.l_name>>" "<<e.state;
}
void find_oldest(employees array[])// oldest person = smallest dob
{
int i;
int index=0
int oldest=1000000000;//dummy variable
for(i=1;i<1000;i++)//1000 is array length
{
if(array[i].dob<oldest)
{
index=i;
oldest=array[i].dob;
}
}
print_person(array[i]);
}
int main()
{
employees array[1000];
read_file(array);
find_oldest(array);
}