Write a program that takes as input five numbers and outputs the mean (average)
ID: 3928945 • Letter: W
Question
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).Explanation / Answer
// 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
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.