Sie sind auf Seite 1von 2

#include<iostream>

#include<cmath>
using namespace std;
class statistics
{
float x[20],f[20],a;
int i,n;
float mean,sf,sfa,v,var,sd,m,mnt;
public:
void read();
void basic();
void variance();
void moments();
};
void statistics::read(void)
{
cout<<"enter the no of statisticsta values \n";
cin>>n;
cout<<"enter the nos & there frequency repectively \n";
for(i=0;i<n;i++)
{
cin>>x[i]>>f[i];
}
cout<<"enter the pt. around which to calculate moments \n";
cin>>a;
}
void statistics::basic (void)
{
sf=0;sfa=0;
for(i=0;i<n;i++)
{
sf=sf+f[i];
sfa=sfa+f[i]*x[i];
}
cout<<"sf = "<<sf<<"\t sfa = "<<sfa<<endl;
mean=sfa/sf;
cout<<"mean = "<<mean<<endl;
}
void statistics::variance(void)
{
v=0;
for(i=0;i<n;i++)
{
v=v+f[i]*pow((x[i]-mean),2);
}
var=v/sf;
cout<<"variance = "<<var<<endl;
sd=sqrt(var);
cout<<"Stanstatisticsrd deviation = "<<sd<<endl;
}
void statistics::moments(void)
{
int j,k=3;
for(j=1;j<k;j++)
{
m=0;
for(i=1;i<n;i++)
{
m=m+f[i]*pow((x[i]-a),j);
}

mnt=m/sf;
cout<<"the "<<j<<"th moments around a="<<a<<" is "<<mnt<<endl;
}
}
int main()
{
statistics call;
call.read();
call.basic();
call.variance();
call.moments();
return 0;
}

Das könnte Ihnen auch gefallen