Computer Science, asked by princessgagan2pdcgcl, 16 days ago

Write a test program that prompts the user to enter 10 numbers and displays then mean and deviation ​

Answers

Answered by honeywell9456
5

Answer:

here is your answer

please start following me and drop me some thanks

Explanation:

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 <iostream>

#include <cmath>

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 :" << "\n";

    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] << ".\n";

    }

    cout << endl;

    cout << "The mean is ";

    cout << average(vals, numVals, sum) << ".\n";

    cout << endl;

    cout << "The standard deviation is: ";

    cout << stanDev(vals, numVals, sum) << ".\n";

}

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);

Similar questions