Question: Write a test program that prompts the user to enter 10 numbers and displays the mean and deviation, as shown in the following sample run:

Write a test program that prompts the user to enter 10 numbers and displays the mean and deviation, as shown in the following sample run:

Your program should contain the following functions:

// Compute the mean of an array of double values double mean(const double x[], int size) // Compute the deviation of double values double deviation(const double x[], int size) 

Write a test program that prompts the user to enter 10 numbers and displays the mean and deviation, as shown in the following sample run:

ex:

Enter ten numbers: 1.9 2.5 3.7 2 1 6 3 4 5 2 The mean is 3.11 The standard deviation is 1.55738

So this what I have:

#include #include

using namespace std;

void displayVals(int vals[], int numVals, int sum); void getVals(int vals[], int numVals); double average(int sum, int numVals); double stanDev(int vals[], double mean, int numVals);

int main() { int numVals=10; int sum = 0; int vals[9];

getVals(vals, numVals); cout << endl; displayVals(vals, numVals, sum); cout << endl;

}

void getVals(int vals[], int numVals) { int index; cout << "Enter ten numbers :" << " "; for (index = 0; index < numVals; index++) { cout << index + 1; cin >> vals[index]; } }

void displayVals(int vals[], int numVals, int sum) { int index; for (index = 0; index < numVals; index++) { cout << index + 1; cout << vals[index] << ". "; }

cout << endl; cout << "The mean is "; cout << average(vals, numVals, sum) << ". ";

cout << endl; cout << "The standard deviation is: "; cout << stanDev(vals, numVals, sum) << ". ";

}

double average(int sum, int numVals) { double dsum = (double)sum; double dnumVals = (double)numVals; return dsum / dnumVals; }

double stanDev(int vals[], double mean, int numVals) { double sum = 0, dVals = 0, value = 0, variance = 0; for (int i = 0; i < numVals; i++) { dVals = (double)vals[i]; value = (dVals - mean)*(dVals - mean); sum += value; variance = sum / (numVals); } return sqrt(variance); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!