# Statistics with C++
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<math.h>
const SZ=100;
class GMean
{
public : float X[SZ],F[SZ],FLX[SZ];
float Tn,sf,sflx,gm,t;
public : void getdata();
void showdata();
void gmean();
};
void GMean :: getdata()
{
cout<<"\nEnter total number of your data : ";
cin>>Tn;
cout<<"\nEnter your data : \n\n";
for(int i=0;i<Tn;i++)
{
cout<<" X "<<i+1<<" : ";
cin>>X[i];
}
cout<<"\nEnter frequencies for above data : \n\n";
for(int j=0;j<Tn;j++)
{
cout<<"Frequency for "<<X[j]<<" : ";
cin>>F[j];
}
}
void GMean :: gmean()
{
sf=0;
for(int i=0;i<Tn;i++)
{
FLX[i] =F[i] * (log10 (X[i]));
sflx+=FLX[i];
sf+=F[i];
}
t= (sflx/(double)sf);
gm= pow(10,t);
}
void GMean :: showdata()
{
cout<<"\n\n*** YOUR DATA IS AS FOLLOWS: ***\n\n";
cout<<"\n\n X \t F \t logX \t F*logX\n ";
for(int i=0;i<Tn;i++)
{ cout<<X[i]<<"\t"<<F[i]<<"\t"<<setprecision(3)<<log10(X[i])<<"\t"<<FLX[i]<<" \n "; }
// cout<<"\n\nNumber of observations = "<<Tn;
// cout<<"\nSummation of Freq.*logX = "<<sflx;
// cout<<"\n\n"<<t;
cout<<"\n\nGeometric mean for your data = "<<gm;
}
void main()
{
GMean GM;
clrscr();
GM.getdata();
GM.gmean();
GM.showdata();
getch();
}
-----------------------------------------------------------------------------------------------------
Out Put :
Enter total number of your data : 9
Enter your Data :
X1 : 130
X2 : 135
X3 : 140
X4 : 145
X5 : 146
X6 : 148
X7 : 149
X8 : 150
X9 : 157
Enter frequencies for above data :
Frequency for 130 : 3
Frequency for 135 : 4
Frequency for 140 : 6
Frequency for 145 : 6
Frequency for 146 : 3
Frequency for 148 : 5
Frequency for 149 : 2
Frequency for 150 : 1
Frequency for 157 : 1
*** YOUR DATA IS AS FOLLOWS: ***
X F logX F*logX
130 3 2.114 6.342
135 4 2.13 8.521
140 6 2.146 12.877
145 6 2.161 12.968
146 3 2.164 6.493
148 5 2.17 10.851
149 2 2.173 4.346
150 1 2.176 2.176
157 1 2.196 2.196
Geometric mean for your data = 142.528
-------------------------------------------------------------------------------------------------------
* please comment if there is any error or if it need corrections.
Happy Coding!
No comments:
Post a Comment