Вы находитесь на странице: 1из 2

/*Create by: Rosmawati binti aminuddin / Nur Rafiqah bt Ridzuan

Students ID: CE110014 / CE110188


Created Date: 21/05/2014
Description of the Program: to write a C++ program that able to compute the
standard deviation of n numbers using the formula given.
*/
#include <iostream>
#include <cmath>
using namespace std;
/*read n that represents number of input. Ensure that the n is not more than the
size
of array x. Then, get the input for array x */
void Get_Input();
//Compute the mean of an array of double values.
double mean (double[] , int);
//Compute the deviation of double values
double deviation(double[] , int);
//display result of mean and deviation
void display(double mean , double deviation);
double mean2;
/*main function*/
int main ()
{//begin main
Get_Input() ;
system ("PAUSE");
return 0 ;
}//end main
//=======================================
//Function definition of Get_Input
//Task Description of Get_Input function
//Task done by: Rosmawati binti aminuddin
// Nur Rafiqah bt Ridzuan
//========================================
void Get_Input()
{
int size=10;
double x[10];
mean2=0.0;
cout << "Please enter the 10 integer numbers:" << endl;
for (int i=0; i<10; i++)
{
cout << "\nEnter 10 integer number = ";
cin>>x[i];
}
cout << "\nThe mean is:" << mean (x,9);
cout << endl;
cout << "The standard deviation is:"<< deviation (x,9) << endl;
system ("PAUSE"); return ;
}
//=======================================
//Function definition of Get_Input
//Task Description of calculate_mean function
//Task done by: Rosmawati binti aminuddin
// Nur Rafiqah bt Ridzuan
//========================================
double mean (double x[], int data)
{
double sum=0;
for ( int i = 0; i <=data; i++ )
{
sum += x[i];
}
mean2=sum/(10.0);
return mean2;
}
//=======================================
//Function definition of calculate_deviation
//Task Description of calculate_deviation function
//Task done by: Rosmawati binti aminuddin
// Nur Rafiqah bt Ridzuan
//========================================
double deviation (double x[], int data)
{
double deviation;
double sum2=0;
for ( int i = 0; i <=data; i++ )
{
sum2 += pow((x[i]-mean2),2.0);
}
deviation= sqrt(sum2/(10-1));
return deviation ;
}
//=======================================
//Function definition of display
//Task Description of display function
//Task done by: Rosmawati binti aminuddin
// Nur Rafiqah bt Ridzuan
//========================================
void display (double mean, double deviation)
{
cout<<"mean"<<mean<<endl;
cout<<"deviation"<<deviation<<endl ;
return ;
}

Вам также может понравиться