Hi all. I am receiving some tutoring this summer, and I'm having a bit of an issue with an assignment. I created a program that reads from a text file, and I'm trying to have the program go in ascending order from an object in my class. I'm trying to have it read the GPAs entered from the text file be what gives the order it's printed on screen. I am using the quicksort algorithm to try to do the sorting. Here's my code for the quicksort (I know it's wrong)
Code:
void QUICKSORT(double GPA [], int l, int r)
{
int i, j, t, p;
i = l;
j = r;
p = GPA[(l+r)/2];
while(i <= j)
{
while (GPA[i] < p)
i++;
while(GPA[j] > p)
j--;
if(i <= j)
{
t = GPA[i];
GPA[i] = GPA[j];
GPA[j] = t;
i++;
j--;
}
}
if(l < j)
QUICKSORT(GPA, l, j);
if(i < r)
QUICKSORT(GPA, i, r);
};
Here is what the class looks like:
Code:
class Students{
private:
string Name;
int ID;
string Major;
double GPA;
string Grade;
public:
string getName(){
return Name;
}
void setName(string x){
Name = x;
}
int getID(){
return ID;
}
void setID(int x){
ID = x;
}
string getMajor(){
return Major;
}
void setMajor(string y){
Major = y;
}
double getGPA(){
return GPA;
}
void setGPA(double x){
GPA = x;
}
string getGrade(){
return Grade;
}
void setGrade (string z){
Grade = z;
}
void printInfo(){
cout << "Student Name: " << Name << endl;
cout << "ID Number: " << ID << endl;
cout << "Major: " << Major << endl;
cout << "Current GPA: " << GPA << endl;
cout << "Class Rank: " << Grade << endl << endl;
}
The file compiles, and does print. However, it's not going in the order that I need it to go in. I know I need to have the Quicksort function called in the int main(), but anywhere I put it, it wouldn't work. What am I doing wrong here????