Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<string> #include<iomanip> #include<fstream> using namespace std; int ma

ID: 3610558 • Letter: #

Question

#include<string>

#include<iomanip>

#include<fstream>

using namespace std;

int main()

{

string filename,egr126("egr126");

int loop=20, ID, count, m,hod;

double grade, hold;

ifstream AAA;

ofstream BBB;

int id [20];

double GRADE [20];

cout << "Enter filename fordata file " << endl;

cin >> filename;

AAA.open(filename.c_str());

BBB.open(egr126.c_str());

if (AAA.fail())

{

cerr << "Error opening inputfile" << filename << endl;

system("pause");

exit(1);

}


for (count=0; count<loop; count++)

{

AAA >> ID >>grade;

id [count]=ID;

GRADE [count]=grade;

}

for (int k=0; k<=(loop-2);++k)

{

m=k;

for (int j=(k+1); j<=(loop-1);++j)

{

if(GRADE[j]>GRADE[m])

m=j;

}

hold=GRADE[m];

GRADE[m]=GRADE[k];

GRADE[k]=hold;

hod=id[m];

id[m]=id[k];

id[k]=hod;

}

for (int c=0; c<loop;c++)

{

cout << setw (8) <<id[c] << setw(8) << GRADE[c] << endl;

BBB << setw (8) <<id[c] << setw(8) << GRADE[c] << endl;

}

AAA.close();

system("pause");

return 0;

}

Explanation / Answer

please rate - thanks it now sorts. remember to enter the file name asegr126.txt. you can't sort 20 numbers if you only have 10,and it was doing largest to smallest. I added range of numbers and largest numbers. I can help with the rest of the program but I need to know ifyou've learned functions yet #include #include #include #include using namespace std; int main() { string filename, egr126("egr126"); int loop=20, ID, count, m, hod; double grade, hold,average; ifstream AAA; ofstream BBB; int id [20]; double GRADE [20]; cout ID;    count++;     }; loop=count; for (int k=0; k