Using the code below, I want to use my sort function to take an Student
array and sort them based on their gpa
component. I have to use the parameters of a Student
array and the size of the array. If you look towards the bottom of my int main
function I try to call on the member sort to sort the array a
but with no avail. The error I get is:
member reference base type
Student [200]
is not a structure or union.
How do I wrote my code to take array a
and say to use the member Sort
on it given the parameters I have to use. Thanks in advance. If this too much please let me know I'll try to specify even more.
class Student
{
private:
string ID, fname, lname, level;
double gpa;
public:
Student();
Student(string id, string first, string last, double Gpa, string grade);
string getID() const;
string getfirst() const;
string getlast() const;
string getlevel() const;
double getGPA() const;
void setID(string id);
void setfirst(string f1);
void setlast(string l1);
void setlevel(string lev);
void setGPA(double GPA1);
friend void Sort(Student studentlist[], int size);
friend ostream& operator <<(ostream& ost, Student S1);
};
int main()
{
ifstream ins;
ofstream outs;
ins.open("input.dat");
outs.open("output.dat");
if(ins.fail())
{
cout << "File not found.";
exit(1);
}
if(outs.fail())
{
cout << "Output file not opened.";
exit(1);
}
Student a[200];
int x = 0;
while(!ins.eof())
{
string id, fnam, lnam, levl;
double point;
ins >> id >> fnam >> lnam >> point >> levl;
a[x].setID(id);
a[x].setfirst(fnam);
a[x].setlast(lnam);
a[x].setGPA(point);
a[x].setlevel(levl);
if(a[x].getID() == "")
{
break;
}
x += 1;
}
if(x == 0)
{
cout << "File is empty" << endl;
return 0;
}
x = x +1;
a.Sort(a, x);
int t=0;
while(t<x)
{
outs << a[t];
t += 1;
}
outs.close();
ins.close();
return 0;
}