2. Write a necessary class to calculate variance &standard deviation of n numbers. Variance = 1/N ? (Xi-A.M.)2 for all i = 1 to N S.D. =variance Where A.M. = 1/N ? X for all i = 1 to N


#include<iostream.h>
#include<conio.h>
#include<math.h>
class cal
{
public:
int x[10];
int N,i,n;
float A_M,VR;
int sum;
public:
void get();
void AM();
void Variance();
void SD();
};
void cal::get()
{
cout<<“\nEnter the value of n : “;
cin>>N;
n=N;
cout<<“\nEnter the “<<N<<” number: “;
for(i=0;i<N;i++)
{
cin>>x[i];
}
}
void cal::AM()
{
sum=0;
for(i=0;i<N;i++)
{
sum=sum+x[i];
}
A_M=(1/n)*sum;
cout<<“\nAM= “<<A_M;
}
void cal::Variance()
{
// AM();
float v,t,s=0;
for(i=0;i<N;i++)
{
v=x[i]-A_M;
t=v*v;
s=s+t;
}
VR=(1/n)*s;
cout<<“\nVR= “<<VR;
}
void cal::SD()
{
float sd;
// Variance();
sd=sqrt(VR);
cout<<“\nSD= “<<sd;
}
void main()
{
cal c;
clrscr();
c.get();
c.AM();
c.Variance();
c.SD();
//c.AM();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s