Well your syntax in the Student class is rather bad on that
SortName() function.
but this looks like a good way of going about it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class Student{
std::string last, first;
float GPA;
public:
Student(std::string var1, std::string var2, float var3){
first = var1;
last = var2;
GPA = var3;
}
std::string getNameFirst(){return first;}
std::string getNameLast(){return last;}
float getScore(){return GPA;}
};
/*
That's a simple class setup, remember that if you're going to sort the classes
then you need to be able to access the name, hence the get'() functions
*/
|
That's a little help, as for the rest I think it'd be better if you did a little more thinking yourself. I'd suggest though that you have some form of data container that you can swap orders around in, an array will do.
Then I'd setup a couple of nest loops, the most outer will keep looping until all in correct order is detected, an inner loop will cycle through the students (overlapping, i.e. 0&1, then 1&2, then 2&3, etc), and i'd have a third loop which cycles through the letters in the names, comparing by alphabetical order.
IF a letter is hit in 1st element that is later in alphabet than 2nd test element then swap them around and signal a bool type to indicate that you found an out of order area.
This bool is used in the most outer loop to check if it's finished... keep looping until this bool is false