Popular Posts

Showing posts with label HARMONIC MEAN for normal data.. Show all posts
Showing posts with label HARMONIC MEAN for normal data.. Show all posts

25 Jan 2014

HARMONIC MEAN for normal data.

# Statistics with C++


//program to calculate the HARMONIC MEAN for given normal data.

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
const SZ=100;
class HMean
{
  public : float Data[SZ],X[SZ];
  float Tn,SX,hm;
  public : void getdata();
  void showdata();
  void hmean();
};

void HMean :: getdata()
{
   cout<<"\n\nEnter total number of data you want to enter ?: ";
   cin>>Tn;
   cout<<"\n\nEnter Your Data : ";
   for(int i=0;i<Tn;i++)
   {
     cin>>Data[i];

   }
}

void HMean :: hmean()
{

   for(int i=0;i<Tn;i++)
   {
     X[i]=1/Data[i];
     SX+=X[i];

   }
   hm=( Tn/SX);
}

void HMean :: showdata()
{
   cout<<"\n\n  X  :  ";
   for(int i=0;i<Tn;i++)
   {  cout<<Data[i]<<"  "; }

   cout<<"\n\n 1/X :  ";
   for(i=0;i<Tn;i++)
   {  cout<<setprecision(3)<<X[i]<<"  ";  }

   cout<<"\n\nNumber of observations = "<<Tn;
   cout<<"\n\n\nHarmonic mean for your data = "<<setprecision(2)<<hm;

}

void main()
{
  HMean HM;
  clrscr();
  HM.getdata();
  HM.hmean();
  HM.showdata();
  getch();

}

-------------------------------------------------------------------------------------------------------

Out Put :


---------------------------------------------------------------------------------------------------------

* Please comment if you find any error and if it need corrections.

Happy Coding!