Thursday, September 18, 2008

Array Standard Deviation Code in C++

PROBLEM: Array in Standard Deviation

Create a C++ program that will ask the user to input 8 numbers separated by blanks. Compute the mean and standard deviation of an array of data and displays the difference between each values and the mean (average of the data). Please research for the formula of the standard deviation. Please refer the output format for display. The program will then ask the user to repeat the process, press y for yes and n for exit.

---------------------------------------------------------------------------------------
#include
#include
#include
#include
using namespace std;
void process();
int main()
{
process();
}
void process()
{
double a[8],total=0,mean=0,d,s2,fsd,bc[8];
float k=0,msd=0;
int b;
char cont='Y';
do{
system("cls");
if(cont=='y' || cont=='Y')
{
cout<<"Enter 8 numbers separated by blanks:\n";
for(b=0;b<8;b++)
{
cin>>a[b];
total=total+a[b];
}
mean=total/8;
cout<<"\n";
cout<<"The mean is: "< for(b=0;b<8;b++)
{
d=a[b]-mean;
bc[b]=d;
k=(d*d)+k;
}
s2=pow(d,2);
msd=s2/8;
fsd=sqrt(k/8);
cout<<"Standard Deviation: "< cout<<"\n\nThe Table of differences between data values and the mean: ";
cout<<"\n\nIndex\t\tItem\t\tDifference";
for(b=0;b<8;b++)
{

cout<<"\n"< }
cout<<"\n";
}
else{
cout<<"Wrong input!\n";
}

cout<<"\nPlease repeat the process? [y for yes][n for no]";
cin>>cont;
}while(cont!='n' && cont!='N');
}

------------------------------------------------------------------------------------
If you like this post will you buy me a beer?


No comments: