#include <iostream> #include <iomanip> #include <fstream> #include <string> usin
ID: 3535766 • Letter: #
Question
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std
int main ()
{
char file [20];
cout << "Enter File Name " << endl;
cin >> file;
ifstream infile (file);
// check if File is Open.
if (infile)
{
int count = 0, grades [30], high = 0, low = 0;
double average = 0;
for ( ; infile >> grades [count ]; count++)
SelectionSort (grades, count );
Print ( grades, count );
CheckGrades (grades, count );
high += GetHighest ( grades, count );
low += GetLowest (grades, count );
average += GetAverage (grades, count );
cout << "Highest grade was " << high << endl;
cout << "Lowest grade was " << low << endl;
cout << setprecision(2)
<< "Average was " << setprecision (2) << average << endl;
cout << endl;
BubbleSort (grades, count);
Print (grades, count );
infile.close ();
}
else cout << "Invalid File " << endl;
return 0;
}
// Print to the screen.
void Print (int grades[], int count)
{
for (int i=0; i < count; i++)
cout << grades [i] << endl;
cout << endl;
}
// SelectionSort function.
void SelectionSort (int grades[], int count )
{
for (int i = 0; i < count; i++ )
{
int largest = i;
for (int j = largest + 1; j< count - 1; j++)
{
if (grades [j] < grades [largest] )
largest = j;
int temp = grades[i];
grades[i] = grades[largest];
grades[largest] + temp;
}
}
}
// BubbleSort function.
void BubbleSort ( int grades[], int count )
{
for (int i = 0; i < count - 1; i++ )
for(int j = 0; j < count - 1; j++)
if (grades [j+1] > grades[j] )
{
int temp = grades [j];
grades [j] =grades [j+1];
grades [j+1] = temp;
}
}
// Cout Grades by Letters and Print to Screen.
void CheckGrades ( int grades [], int count )
{
int A = 0, B = 0, C = 0, D = 0, F = 0;
for ( int i = 0; i < count - 1; i ++)
if (grades [i] >= 90 && grades [i] <= 100) A++;
else if (grades [i] >= 80 && grades [i] <= 89 ) B++;
else if (grades [i] >= 70 && grades [i] <= 79) C++;
else if (grades [i] >= 60 && grades [i] <= 69 ) D++;
else if (grades [i] <= 59) F++;
if ( A == 1 )
cout << "There was " << A << " A " << endl;
else if ( A != 0 && A != 1 )
cout << "There were " << A << " A's" << endl;
if ( B==1 )
cout << "There was " << B << " B " << endl;
else if ( B != 0 && B != 1 )
cout << "There were " << B << "B's" << endl;
if ( C == 1)
cout << "There was " << C << " C " << endl;
else if ( C != 0 && C != 1)
cout << "There were " << C << " C's " << endl;
if ( D == 1 )
cout << "There was " << D << " D " << endl;
else if ( D != 0 && D != 1 )
cout << "There were " << D << " D's" << endl;
if ( F == 1 )
cout << "There was " << F << " F " << endl;
else if ( F != 0 && F != 1 )
cout << "There were " << F << " F's " << endl;
cout << endl;
}
// Function to GetHighest Grade.
int GetHighest ( int g[], int count )
{
int hi = g [0];
for ( int i = 1; i < count ; i++ )
if ( g [i] > hi ) hi = g [i];
return hi;
}
// Fuction to GetLowest Grade.
int GetLowest ( int g[], int count )
{
int low = g[0];
for ( int i = 1; i < count; i++ )
if ( g[i] < low ) low = g [i];
return low;
}
// Function Get Average.
float GetAverage (int g[], int count )
{
float sum = 0;
for ( int i = 0; i < count; i++ )
sum += g [i];
return sum / count;
}
how to fix htis program, i need help?
Explanation / Answer
what is the problem
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.