1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int buildAr(int[], double[], double[]);
void displayAr(int[], double[], double[], int);
void sortAr(int[], double[], double[], int);
void change(int[], int, int);
void change2(double[], int, int);
#define max 20
int main ()
{
int studentId[max];
int count;
double programAverage[max], testAverage[max], overallAverage[max];
count = buildAr(studentId, programAverage, testAverage);
if (count > 0)
{
cout << "\t\t\tThe UNSORTED student information" << endl << endl;
displayAr(studentId, programAverage, testAverage, count);
system("pause");
sortAr(studentId, programAverage, testAverage, count);
cout << "\t\t\tThe SORTED student information" << endl << endl;
displayAr(studentId, programAverage, testAverage, count);
}
system("pause");
return 0;
}
// Build program that builds the arrays from the infomation provided in the input file //
int buildAr(int studentId[], double programAverage[], double testAverage[])
{
ifstream inFile;
int i = 0;
inFile.open( "averages.txt" );
if ( inFile.fail() )
{
cout << "input file did not open";
exit(0);
}
inFile >> studentId[i];
while (inFile)
{
inFile >> programAverage[i] >> testAverage[i];
i++;
inFile >> studentId[i];
}
inFile.close();
return i;
}
// Display program that displays the information in neat columns //
void displayAr(int studentId[], double programAverage[], double testAverage[], int count)
{
double overallAverage[max];
int i;
cout << "Student ID Program Average Test Average Overall Average" << endl;
cout << "-------------------------------------------------------------------------------\n";
for(i = 0; i < count; i++)
{
overallAverage[i] = (programAverage[i] * 0.4) + (testAverage[i] * 0.6);
cout << setw(8) << right << studentId[i];
cout <<setiosflags(ios:: fixed | ios:: showpoint) << setprecision(2) << "\t\t";
cout << programAverage[i] << left << "\t\t ";
cout << testAverage[i] << "\t\t ";
cout << overallAverage[i];
}
cout << "\n\n\n";
}
// sorting program that sorts the data in ascending student ID //
void sortAr(int studentId[], double programAverage[], double testAverage[], int count)
{
double temp;
int i,j, temp1;
for ( i=0; i < count; i++)
for (j=i+1; j < count; j++)
if( studentId[j] < studentId[i])
{
temp1 = studentId[i];
studentId[i] = studentId[j];
studentId[j] = temp1;
temp = programAverage[i];
programAverage[i] = programAverage[j];
programAverage[j] = temp;
temp = testAverage[i];
testAverage[i] = testAverage[j];
testAverage[j] = temp;
}
}
|