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
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const int STUDENT = 300;
float gradecalc(float grade[STUDENT]), grade[STUDENT], avg, high, low, med;
int i, j, temp;
char ans;
int main(float avg, float high, float low, float med)
{
for(i = 0; i < STUDENT; i ++)
{
cout << "Please enter grade: ";
cin >> grade[i];
for ( i = 0; i < (STUDENT - 1); i++)
{
for(j = 1; j < STUDENT; j++)
{
if (grade[j] < grade[j-1])
{
temp = grade[j];
grade[j] = grade[j-1];
grade[j-1] = temp;
}
}
if ( grade[i] < 0)
{
cout << "\nNumber Grade"
<< "\n------- -------"
<< endl;
cout << setw(2) << i
<< setw(9) << grade[i];
avg = gradecalc(grade);
high = gradecalc(grade);
low = gradecalc(grade);
med = gradecalc(grade);
cout << "\n\nMedian Grade: " << med
<< "\nLowest Grade: " << low
<< "\nThe class average: " << avg
<< "\nHighest Grade is: " << high;
cout << "\n\nWould you like to start a new class?"
<< "\n('Y' or 'N'): ";
cin >> ans;
if(ans == 'Y' || ans == 'y')
{
continue;
}
else
{
break;
}
}
else
{
continue;
}
}
}
return 0;
}
float gradecalc(float grade[STUDENT])
{
float sum;
sum = 0;
high = grade[0];
low = grade[0];
for(i = 0; i >= 0 && i < STUDENT; i ++)
sum = sum + grade[i];
avg = sum / i++;
high = grade[i];
low = grade[0];
if(i % 2 == 0)
med = grade[i/2];
else
med = (grade[i/2] + grade[i/2 + 1])/2;
return avg, high, low, med;
}
|