Write a program that takes as input five numbers and outputs

Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are X_1, X_2, . X_3, X_4, X_5 then the mean is equal to X = (X_1 + X_2 + X_3+ X_4 + X_5)/5 and the standard deviation is: squareroot (Xl - X)^2 + (X2 - X)^2 + (X3 - X)^2 + (X4 - X)^2 + (X5 - X)^2 Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. Turn-in a print out of your source code and upload your source code to Sakai (lab_4 folder).

Solution

// C++ code to determine mean and standard deviation

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <stdlib.h>   
#include <math.h>

using namespace std;


int main()
{
double X1,X2,X3,X4,X5;
double mean, standard_deviation;

cout << \"Enter first number: \";
cin >> X1;
cout << \"Enter second number: \";
cin >> X2;
cout << \"Enter third number: \";
cin >> X3;
cout << \"Enter fourth number: \";
cin >> X4;
cout << \"Enter fifth number: \";
cin >> X5;

mean = (X1+X2+X3+X4+X5)/5;

standard_deviation = sqrt((pow((X1-mean),2) + pow((X2-mean),2) + pow((X3-mean),2) + pow((X4-mean),2) + pow((X5-mean),2) )/5);

cout << \"\ Mean: \" << mean << endl;
cout << \"Standard Deviation: \" << standard_deviation << endl;

return 0;
}

/*
output:

Enter first number: .5
Enter second number: 2.3
Enter third number: 4.2
Enter fourth number: 1.4
Enter fifth number: 6.4

Mean: 2.96
Standard Deviation: 2.11149

*/

 Write a program that takes as input five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are X_1, X_2, . X_3, X_4,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site