string fname;
string lname;
string major;
double gpa;};
// studentstudent e[100];
int n; void load(){ifstream studentFile("students.txt", ios::in);
while(studentFile>>e[n].fname>>e[n].lname>>e[n].major>>e[n].gpa){n++;}
//WHILE}
// LOAD the student void display(){cout<<setiosflags(ios::left)<<setw(15)<<"First Name"<<setw(15)<<"Last Name";
cout<<setw(15)<<"major"<<setw(15)<<"gpa";
cout<<endl<<endl;
cout<<setiosflags(ios::fixed|ios::showpoint|ios::left);
for(int i=0;i<n;i++){ if(e[i].fname!=" "){cout<<setiosflags(ios::left)<<setw(15)<<e[i].fname<<setw(15)<<e[i].lname;
cout<<setprecision(2)<<setiosflags(ios::left)<<setw(15)<<e[i].major;
cout<<setw(15)<<e[i].gpa;
cout<<resetiosflags(ios::left)<<endl;}
//IF}
//FOR}
//THIS FUNCTION DISPLAYS ALL RECORDS IN ARRAY int swap(int a, int b){student temp;
temp=e[a];
e[a]=e[b];
e[b]=temp;
return 0;}
//swapmain(){
load();
char
choice='0';while
(choice!='e'&&choice!='E'){cout<<"1. Display the original students' Records"<<endl;
cout<<"2. Sorting the Records by GPA"<<endl;
cout<<"Enter the number of your choice:";
cin>>choice;
cout<<endl;
switch
(choice){case
'1': display(); break;case
'2': int n=5 ,i,j;for(i=0;i<n-1;i++){
j=i+1;
for(;j<n;j++){
if(e[i].gpa>e[j].gpa)
{swap(i,j);}
}
}
//END idisplay();
break;}
// switch}
// while}
//MAIN