***Note that his is a beginners C++ program and we can only use beginners inform
ID: 3703329 • Letter: #
Question
***Note that his is a beginners C++ program and we can only use beginners information***
Statistics is the mathematical science involving the collection, analysis, and interpretation of data. Fundamentally, through statistics we can capture and comprehend the variability of the data collected for different engineering experiments and simulations. Variability of data essentially refers to the inconsistencies of the captured data related to a particular phenomenon or system behavior. A daily example is the mileage performance of a car. Even for the same car, every gallon of gas doesn’t provide us with the same mileage. This phenomena can be controlled by many factors – city vs highway driving, changes in the condition of the vehicle over time (wear and tear, etc.), and so forth. Applying statistical analysis in such domains will help us ascertain the factors which play an influential role and the decision making process to refine and improve the system or the phenomena.
Often during engineering design, physical laws are applied to the system or the product. However, these designs are ideal in nature and mightn’t behave exactly as hypothesized in the real world. Different criterion need to be designed and statistically tested for their performance in the real world scenario. This technique is known as statistical inference.
Statistics have well-found applications in different disciplines of science and engineering, ranging from (but not limited to) biology, quantitative psychology, thermodynamics, physics, mechanics, and so on.
In many data collection process, some data values or observations may lie considerably away from the majority of the data values or observations. While performing statistical analysis, these data values are typically dropped before applying any inferential techniques. You are presented with a single dimensional array which can store up to 10 floating-point values provided as input by the user. Write a program in C++ that computes and displays the maximum, minimum, mean, and standard deviation of the observations stored in the array given as input by the user. Additionally, all data values or observations which are more or less than one standard deviation from the computed mean should be dropped and the new resulting array along with its max, min, mean, and std. dev. values should be computed and displayed.
Note that your program must be designed using functions. Functions for the following functionalities must be present – to receive user input, to compute max, mix, mean, standard deviation, and to display the required outputs.
Formulas:
Mean (??):
?? =
? ???? ?? 1 ??
where, N is the total number of observations or values, and ???? (1 ? ?? ? ??)is one of the individual observations. Variance (??2):
??2 =
? (???? ???)2 ?? 1 ??
Standard Deviation (????):
???? = ?? To compute boundary conditions for dropping data values or observations: ?? ?(????) ?? +(????)
Input Case:
6.53, 33.38, 14.34, 76.83, 44.67, 25.76, 88.11, 5.45, 57.89, 63.34
Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
double mean(int[],int);
int minn(int[],int);
int maxx(int[],int);
void sort(int[],int);
double median(int[],int);
double deviation(int x[], int n);
int main()
{int x[100];
int i=0,j,min,max;
do
{cout<<"Enter a number (<0 when done) ";
cin>>x[i];
i++;
}while(i<100&&x[i-1]>=0);
if(x[i-1]<0) //if sentinel, and not that used all 100 spaces
i--;
cout<<" Your numbers are: ";
for(j=0;j<i;j++)
{cout<<x[j]<<" ";
if((j+1)%20==0) //20 numbers per line
cout<<endl;
}
cout<<endl;
min=minn(x,i);
max=maxx(x,i);
cout<<"Minimum is: "<<min<<" ";
cout<<"Maximum is: "<<max<<" ";
cout<<"Standard Deviation is: "<<deviation(x, i)<<" ";
cout<<"The average is "<<mean(x,i)<<" ";
cout<<"Median is: "<<median(x,i)<<" ";
system("pause");
return 0;
}
int minn(int x[],int n)
{int i,min;
min=x[0];
for(i=1;i<n;i++)
if(x[i]<min)
min=x[i];
return min;
}
int maxx(int x[],int n)
{int i,max;
max=x[0];
for(i=1;i<n;i++)
if(x[i]>max)
max=x[i];
return max;
}
double mean(int x[],int n)
{int i,sum=0;
for(i=0;i<n;i++)
sum+=x[i];
return (double)sum/n;
}
double median (int x[], int n)
{sort(x,n);
if(n%2==0)
return ((double)(x[n/2-1]+x[n/2])/2.);
else
return x[n/2];
}
void sort (int x[], int n )
{int i,j,t;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(x[i]>x[j])
{t=x[i];
x[i]=x[j];
x[j]=t;
}
}
double deviation(int x[], int n)
{
double sum_sqr=0.0;//declare variable of the double data type.
double avg=mean(x,n);
int i;
for (i = 0; i < n; i++)
{
sum_sqr += pow(x[i] - avg, 2);
}
double variance = sum_sqr / (n-1);//claculate variance
return(sqrt(variance));//value of deviation
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.