Problem : Compute the mean and standard deviation of a set of four values This p
ID: 3630972 • Letter: P
Question
Problem : Compute the mean and standard deviation of a set of four values
This project is designed to exercise the use of arithmetic expressions in a C++ program to do computation.
Use Visual C++ to write your program.
The problem to solve is the following:
Write a C++ program that computes the mean and standard deviation of a set of four integer values. The mean is the sum of the four values divided by 4, i.e.,
x = (x1 + x2 + x3 + x4) / 4
where x1, x2, x3, and x4 are the four integer values and x the mean. The formula for the standard deviation is:
Note that although the individual values are integers, the results are floating-point values. Be sure that your program meets the following three requirements:
1. Four integer values should be declared as named constants (You can determine the values you want to use in the declarations).
2. All the output should be directed to the screen.
3. Use proper formatting and appropriate comments in your code. The output should be clearly labeled and neatly formatted. Your program should print out the four integer values, the mean, and the standard deviation in separate lines, each properly labeled.
That is what i have done so far:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
/* Bryce Romero
CS 1410
Project 2
Date: (10/16/2011)
This C++ program that computes the mean and standard deviation of a set of four integer values. */
//Program name: Project2
int main(void)
{
float X1, X2, X3, X4;
float mean;
float StandardDeviation;
cout<<"Enter the first number ---> ";
cin>>X1;
cout<<"Enter the second number ---> ";
cin>>X2;
cout<<"Enter the third number ---> ";
cin>>X3;
cout<<"Enter the fourth number ---> ";
cin>>X4;
mean=(X1+X2+X3+X4)/4;
StandardDeviation = sqrt(((pow(X1-mean,2)) + (pow(X2-mean,2)) +
(pow(X3-mean,2)) + (pow(X4-mean,2)))/ 4);
cout<<"Mean ="<<mean<<endl;
cout<<"StandardDeviation ="<< StandardDeviation<<endl;
cin.get(); cin.get();
return 0;
}
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
/* Bryce Romero
CS 1410
Project 2
Date: (10/16/2011)
This C++ program that computes the mean and standard deviation of a set of four integer values. */
//Program name: Project2
int main(void)
{
float X1, X2, X3, X4;
float mean;
float StandardDeviation;
cout<<"Enter the first number ---> ";
cin>>X1;
cout<<"Enter the second number ---> ";
cin>>X2;
cout<<"Enter the third number ---> ";
cin>>X3;
cout<<"Enter the fourth number ---> ";
cin>>X4;
mean=(X1+X2+X3+X4)/4;
StandardDeviation = sqrt(((pow(X1-mean,2)) + (pow(X2-mean,2)) +
(pow(X3-mean,2)) + (pow(X4-mean,2)))/ 4);
cout <<fixed;
cout<<setprecision(2) << "Mean ="<<mean<<endl;
cout<<setprecision(2) << "StandardDeviation ="<< StandardDeviation<<endl;
cin.get(); cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.