Ok....I'm stuck again...I'm wondering if there is a way to sort the following code, so that I can pick out the highest value. I don't believe that I can make it into a list, since they are in parallel arrays. I'm hoping not to have to do a long set of sentences, but rather a quicker way.....Any ideas? Several people have told me that it would be much much easier if my code were in a 2D array.....how would I do that?
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
double CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60],
int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60],
int Q5[60], int Q6[60], int Final[60], int i);
void main()
{
ifstream students;
ofstream out;
string fname[60];
string studentid[60];
string lname[60];
string id[60];
int Q1[60];
int Q2[60];
int Q3[60];
int MidTerm[60];
int Q4[60];
int Q5[60];
int Q6[60];
int Final[60];
string file;
int i;
cout << "Enter name of file" << endl;
cin >> file; file += ".txt";
students.open(file.c_str());
if(students)
{
out.open("CompleteReport.txt");
out << "Student Grade Report:" << endl;
cout << fixed << setprecision(1);
out << fixed << setprecision(1);
cout << endl
<< "StudentID LastName FirstName Q1 Q2 Q3 Mid Q4 Q5 Q6 Final Avg. Grade"
<< endl;
cout << "--------------------------------------------------------------------------------------------"
<<endl;
out << "StudentID LastName FirstName Q1 Q2 Q3 Mid Q4 Q5 Q6 Final Avg. Grade"
<< endl;
out << "--------------------------------------------------------------------------------------------"
<<endl;
for (i = 0; i < 6; ++i )
{
if (students >> studentid[i] >> fname[i] >> lname[i] >> Q1[i] >> Q2[i] >> Q3[i] >> MidTerm[i]
>> Q4[i] >> Q5[i] >> Q6[i] >> Final[i])
{
cout << left << setw(13) << studentid[i] << setw(12) << fname[i] << setw(12) << lname[i] << setw(7)
<< Q1[i] << setw(7) << Q2[i] << setw(7) << Q3[i] << setw(7) << MidTerm[i] << setw(8)
<< Q4[i] << setw(7) << Q5[i] << setw(8) << Q6[i] << setw(8) << Final[i] <<
CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final, i);
out << left << setw(13) << studentid[i] << setw(12) << fname[i] << setw(8) << lname[i] << setw(7)
<< Q1[i] << setw(7) << Q2[i] << setw(7) << Q3[i] << setw(7) << MidTerm[i] << setw(8)
<< Q4[i] << setw(7) << Q5[i] << setw(8) << Q6[i] << setw(8) << Final[i] <<
CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final, i);
cout << endl;
}
else
{
break;
}
}
students.close();
}
}
double CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60],
int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60], int Q5[60],
int Q6[60], int Final[60],int i)
{
double average1, average2, average3, average4, average5, average6;
int list[] = {Q1[i], Q2[i], Q3[i], MidTerm[i], Q4[i], Q5[i], Q6[i], Final[i]};
int i;
average1 = (Q2[i] + Q3[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 8;
average2 = (Q1[i] + Q3[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 8;
average3 = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q5[i] + Q6[i] + Final[i]) / 8;
average4 = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q5[i] + Q6[i] + Final[i]) / 8;
average5 = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q4[i] + Q6[i] + Final[i]) / 8;
average6 = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q4[i] + Q5[i] + Final[i]) / 8;
if (Q1[i] <= Q2[i] && Q3[i] && Q4[i] && Q5[i] && Q6[i])
return average1;
else if (Q2[i] <= Q1[i] && Q3[i] && Q4[i] && Q5[i] && Q6[i])
return average2;
else if (Q3[i] <= Q1[i] && Q2[i] && Q4[i] && Q5[i] && Q6[i])
return average3;
else if (Q4[i] <= Q1[i] && Q2[i] && Q3[i] && Q5[i] && Q6[i])
return average4;
else if (Q5[i] <= Q1[i] && Q2[i] && Q3[i] && Q4[i] && Q6[i])
return average5;
else if (Q6[i] <= Q1[i] && Q2[i] && Q3[i] && Q4[i] && Q5[i])
return average6;
}