Well, this seems a bit closer, but it's still a bit muddled in places. Before looking at the sort function (sorting as a topic can cause problems as the logic can be tricky), let's look at something a bit simpler. That is, the showArray() function. I think when you get this one working, the sort will also be easier.
The code posted above does not compile, it has many inconsistencies.
Let's look at the function
showArray()
. Its purpose is to print the contents of the array of
Student
objects.
Well then, let's start with the function header.
void showArray (double array[], int size, string name)
Well, the first parameter should be an array of Students. But instead it is declared as an array of doubles. The second parameter, size is good and makes sense. But what about the third parameter, string name. That should not be there at all. The name of each student is already to be found contained within the Student object.
So, change the function header like this:
|
void showArray (Student array[], int size)
|
In order to get this to compile, the structure Student must be declared before it, so move that struct so it is above the function, like this:
1 2 3 4 5 6 7 8
|
struct Student
{
string name;
double testScores;
};
void showArray (Student array[], int size)
{
|
Now when it comes to displaying the array contents, you just need to access the member variables, like this:
array[count].name
and
array[count].testScores
Armed with this understanding, you should now be able to get the
showArray()
function working. When that is done, you can apply exactly the same ideas to the
selectionSort()
function.