Got a question for you guys, so my program reads a file type which looks like this...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Michelle 71
Marcie 99
David 42
Rebecca 83
Jonathan 79
Matthew 77
Rose 7
Melanie 75
Kimberly 73
Roger 74
Scott 76
Bradley 77
Drextell 10
Heidi 70
Alan 68
Pearl 13
Jeanne 43
Heber 55
Here is whats in the header of the class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class StudentStat
{
private:
int Size;
string Names[20];
int Scores[20];
double Avg, StDev, Median;
void Sortem();
void Calc_Avg();
void Calc_StDev();
void Calc_Median();
StudentStat(); // hide the default constructor from user
public:
StudentStat(char *); // Argument is input filename
string getName(int); // return the name at position on the list
int getScore(int); // return score at position on the list
double getStatistic(string); // retrieve "Avg", "StD", "Med", "High", "Low", "Range"
};
Here is the function that reads the file and stores it into the Names or Scores array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
StudentStat::StudentStat(char * fname)
{
Avg = StDev = Median = -1.0; // Initialize values before reading
Size = 0;
// TODO: READ DATA FROM INPUT FILE
ifstream file(fname);
if(!file)
{
cout << "Couldn't open file!" << endl;
}
while(file >> Names[Size] >> Scores[Size]) // goes through file sotring strings in the Names and ints in the Scores
{
++Size;
}
file.close();
// Sort the names/scores in descending order
Sortem();
}
So as of right now the names are stored in a Names string array and the scores are saved in a Score int array. So my question is where do I begin with my bubble sort? I need it to put the scores in descending order so from greatest score to lowest but I need the Names in the string array to still be connected to the number from the list. Does that make sense? If anyone could help or if theres any questions that I need to explain in more depth let me know. Never done a bubble sort before so not sure where to begin. Thanks in advanced.