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
|
#include <iostream>
#include <iomanip> //setw(), fixed, setprecision()
#include <cmath> //pow(), sqrt()
using namespace std;
int main()
{
//Data Abstraction
int number_1, //User Input
number_2, //User Input
number_3, //User Input
number_4, //User Input
number_5; //User Input
double arithmetic, //Calculated Values
geometric, //Calculated Values
harmonic, //Calculated Values
standard; //Calculated Values
//Input
cout << "Enter five numbers:" <<endl;
cin >> number_1
>> number_2
>> number_3
>> number_4
>> number_5;
//Process
arithmetic = ( (number_1) + (number_2)
+ (number_3) + (number_4) + (number_5)) / (5);
geometric = pow (((number_1) + (number_2)
+ (number_3) + (number_4) + (number_5)), (1/5));
harmonic = (5) / ((1 / number_1) + (1 / number_2)
+ (1 / number_3) + (1 / number_4) + (1 / number_5));
standard = sqrt( pow((number_1 - arithmetic), 2)
+ pow((number_2 - arithmetic), 2)
+ pow((number_3 - arithmetic), 2)
+ pow((number_4 - arithmetic), 2)
+ pow((number_5 - arithmetic), 2));
//Output
cout << "Result:" << endl
<< endl;
cout << "Data:" << endl;
cout << number_1 << endl;
cout << number_2 << endl;
cout << number_1 << endl;
cout << number_4 << endl;
cout << number_5 << endl
<< endl;
cout << fixed << showpoint << setprecision(2);
cout << "Arithmetic mean" << setw(11) << "= " << arithmetic << endl;
cout << "Geometric mean" << setw(11) << "= " << geometric << endl;
cout << "Harmonic mean" << setw(11) << "= " << harmonic << endl;
cout << "Standard Deviation\t" << "= " << standard << endl;
return 0;
}
|