I\'m stuck on ordering the average grade from greatest to least. #include <iostr
ID: 3666676 • Letter: I
Question
I'm stuck on ordering the average grade from greatest to least.
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
struct student_info
{
int ids;
double score1, score2;
};
int main()
{
student_info access[30];
int i = 0;
string filename;
ifstream fin;
ofstream fout;
cout << "Enter an input file: ";
getline(cin, filename);
fin.open(filename.c_str());
if (fin.fail())
{
cout << "File failed to open.";
exit(1);
}
int input;
fin >> input;
while (!fin.eof())
{
fin >> access[i].ids;
fin >> access[i].score1;
fin >> access[i].score2;
i++;
}
cout << "--------------------------" << endl << "Course Report" << endl << "--------------------------" << endl;
for (int i = 0; i < input; i++)
{
cout << access[i].ids << " - " << (access[i].score1+access[i].score2)/2;
if ((access[i].score1+access[i].score2)/2 >= 90.0)
cout << " (A)" << endl;
else if ((access[i].score1+access[i].score2)/2 >= 80.0 && (access[i].score1+access[i].score2)/2 <= 89.9)
cout << " (B)" << endl;
else if ((access[i].score1+access[i].score2)/2 >= 70.0 && (access[i].score1+access[i].score2)/2 <= 79.9)
cout << " (C)" << endl;
else if ((access[i].score1+access[i].score2)/2 >= 60.0 && (access[i].score1+access[i].score2)/2 <= 69.9)
cout << " (D)" << endl;
else if ((access[i].score1+access[i].score2)/2 < 60.0)
cout << " (F)" << endl;
}
cout << "--------------------------";
}
Explanation / Answer
Once you determine the solution i.e Displaying grades based on obtained averages.You must apply any sorting algorithm.So that it sorts in Ascending or Descending order.Then reprint the results.You various ap;proaches of sorting techniques like bubble sort,insertion sort,mergesort,quick sort where quick sort being the best one of al