heres my main
int main(){
int hours[50], cnt = 0;
char grades[50], gpaForOneClass[50];
string course[50];
float gpa = 0.0, totalHours = 0, gpaSum = 0;
gradevalue in;
while (1)
{
cout<<"\nEnter a course, the letter grade received, and the credit hours. "<<endl;
cin >> course[cnt];
if (course[cnt] == "quit" || course[cnt] == "QUIT") break;//ends input when quit or QUIT is typed
cin >> grades[cnt];
cin >> hours[cnt];
in = convert(in, grades[cnt]); //converts letter input into right value
gpaForOneClass[cnt] = grade(in, hours[cnt]); //gets gpa total for one class
op_grade(in); //outputs grade letter
gpaSum += gpaForOneClass[cnt]; //totals up gpa
totalHours = totalHours + hours[cnt]; //totals up hours
cnt = cnt + 1;
}
gpa = gpaAvg(gpaSum, totalHours); //calls gpa function
header(); //calls header of table
for (int b = 0; b < cnt; b++) //puts the information into the table
{
bsort(course, cnt); // calls bsort function
cout<<course[b]<<" "<<hours[b]<<" "<<grades[b]<<endl;
}
cout<<"The total GPA is "<<gpa<<" And you attempted "<<totalHours<<" hours."<<endl;
cin>>cnt;
return 0;
}
and here is my bsort function:
void bsort(string course[], const int cnt) //This bubblesort is used to put the courses into
{ //alphabetical order
int i = 0, j = 0;
string temp;
for (i = 1; i < cnt; i++);
{
for (j = 0; j < cnt - i; j++);
{
if (course[j] > course[j+1])
{
temp = course[j];
course[j] = course[j+1];
course[j+1] = temp;
}
}
}
}
The problem is that it will sort the course string. However, i need the attatched parallel arrays to be sorted along with it.
Example Input:
phys112 C 3
cs110 A 4
Example Output:
cs110 C 3
phys112 A 4
I need the grades and the hours to go along with the corresponding input.
I have no clue what I need to do now to do this that wouldn't be a pain in the butt. I know I could save it all into one array, get them output sorted, then break it back into seperate arrays....
Please tell me there is an easier way than this because even though I know you can do it that way, I dont know exactly how to make the code for that.
Thanks.