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
|
#include <iostream>
using namespace std;
int getnumGrades();
void getGrades(double grades [], int size);
void selectionSort(double grades [], int size);
double findMed(double grades [], int size);
void showGrades(double grades [], int size)
{
for (int i = 0; i < size; ++i)
std::cout << grades[i] << ' ';
std::cout << '\n';
}
int main()
{
double grades[20], size;
size = getnumGrades();
getGrades(grades, size);
std::cout << "Before sort: ";
showGrades(grades, size);
selectionSort(grades, size);
std::cout << "After sort: ";
showGrades(grades, size);
double median = findMed(grades, size);
cout << "The median grade is " << median << endl;
return 0;
}
int getnumGrades()
{
int numGrades;
cout << "Please enter the number of grades" << endl;
cin >> numGrades;
return numGrades;
}
void getGrades(double grades [], int size)
{
int i;
cout << "Please enter your grades" << endl;
for (i = 0; i < size; i++)
{
cin >> grades[i];
}
}
|
Please enter the number of grades
4
Please enter your grades
1
2.2
3.2
4
Before sort: 1 2.2 3.2 4
After sort: 1 2 3 4
The median grade is 2.5
Press any key to continue . . . |