This is my assignment. It is due at 11:59PM so I could use help fast. I have a lot of other classes so I don't have much time and I'm trying to get points to pass this class.
The standard deviation of a list of numbers is measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are clustered close to the average. If the standard deviation is large, the numbers are scattered far from the average. The sample standard deviation S, for a list of N numbers x is defined as follows:
S= √((∑_(i=0)^N▒(x_i-x ̅ )^2 )/(N-1))
where x ̅ is the average of the N numbers x1, x2, …. Define a function that takes a partially filled array of numbers as its arguments and returns the standard deviation of the numbers in the partially filled array. Since a partially filled array requires two arguments, the function will actually have two formal parameters: an array parameter and a formal parameter of type int that gives the number of array positions used. Embed your function in a suitable test program.
The numbers in the array will be of type double. The do-while loop inside main() reads in numbers and put them into the array. This do-while loop should continue to read in numbers until either: the user types a negative number, or 100 numbers (hint: MAXSIZE) have been read. Write the condition for the do-while where specified.
Then write a function that will accept an array and print out the contents of the array. This function should accept an array and the number of elements that are to be printed. Before writing the code for this function, write the comments.
Then write another function that will accept an array and calculate the standard deviation of the elements of the array. This function should accept an array and the number of elements that are to be printed. Before writing the code for this function, write the comments. This function will also call the average function, which is provided for you.
I will put my code in the next post. I'm not sure if I'm supposed to change the function or variable identifiers. I'm just going to leave them since I have little time. I don't have much time so it's a little hard to think very clearly right now so my code might not be that great.
#include <iostream>
usingnamespace std;
void PrintArray(constdouble [], int);
double stdDev(double [], int);
double average(double [], int);
constint MAXSIZE = 100;
int main()
{
double array1[100];
int i = 0;
double somenumber;
do
{
cout << "Please enter a number to enter into the array or a negative number to stop."<<endl;
cin >> somenumber;
if (somenumber >= 0)
{
array1[i] = somenumber;
i++;
}
} while (somenumber > 0 || somenumber < MAXSIZE);
cout << "There were " << i << " numbers entered into the array." << endl;
PrintArray (a1[i], size);
stdDev (s[], size);
return 0;
}
//This function prints to the screen the values contained in the array. The memory space of the
//indentifer is passed along.
void PrintArray(constdouble a1[i], int size)
{
count << "The contents of the array are: " << a1[] << endl;
}
//This function calculates and returns the standard deviation of the array. The memory location of the
//array is passed to it.
double stdDev(double s[], int size)
{
double temp(0);
temp = ((pow(average(s[], size)),2))/ size-1)
return (temp);
}
// This function computes the average of the elements of the array
// Input (Arguments): the array itself and the array capacity (portion of array used)
// Output: the average, as a double
double average(double s[], int size)
{
double sum = 0;
for(int i = 0; i < size; i++) {
sum += s[i];
}
return sum / size;
}