Showing posts with label data structure. Show all posts
Showing posts with label data structure. Show all posts

Geometric mean

The geometric mean, in mathematics, is a type of mean or average, which indicates the central tendency or typical value of a set of numbers. It is similar to the arithmetic mean, which is what most people think of with the word "average", except that instead of adding the set of numbers and then dividing the sum by the count of numbers in the set, n, the numbers are multiplied and then the nth root of the resulting product is taken.
The following program will give you the geometric mean

#include < iostream >
#include < cmath >
using namespace std;
int main ()
{
//Data Abstraction
int grade1, grade2, grade3, grade4, grade5;
double average;
double stdDev;
double geoMean;
double harMean;

//Data Input
cout << "Enter Grades: "; cin >> grade1;
cin >> grade2;
cin >> grade3;
cin >> grade4;
cin >> grade5;

average = (grade1 + grade2 + grade3 + grade4 + grade5) / 5.0;

geoMean = pow(grade1 * grade2 * grade3 * grade4 * grade5);
geoMean = pow(geoMean, 0.2);

harMean = (1.0/grade1 + 1.0/grade2 + 1.0/grade3 + 1.0/grade4 + 1.0/grade5);
harMean = 5.0 / harMean;


stdDev = pow(grade1 - average, 2.0);
stdDev = stdDev + pow(grade2 - average, 2.0);
stdDev = stdDev + pow(grade3 - average, 2.0);
stdDev = stdDev + pow(grade4 - average, 2.0);
stdDev = stdDev + pow(grade5 - average, 2.0);
stdDev = stdDev / 5.0;
stdDev = sqrt(stdDev);

//Data Output
cout << "Data: " << endl << endl;
cout << grade1 << endl;
cout << grade2 << endl;
cout << grade3 << endl;
cout << grade4 << endl;
cout << grade5 << endl << endl;
cout << "Results:" << endl << endl;
cout << "Average: " << average;
cout << "\nGeometric Mean: " << geoMean;
cout << "\nHarmonic Mean: " << harMean;
cout << "\nStandard Deviant: " << stdDev;

cin.get();
cin.get();
return 0;
}

BeleTPL.com

Popular Posts