(Using C++ codes) Exercise #2: Mean and Standard Deviation Write a program that
ID: 3819356 • Letter: #
Question
(Using C++ codes)
Exercise #2: Mean and Standard Deviation Write a program that prompts the user to enter integer values for the array of size N (in this case N is 6). The program then calculates mean and standard deviation for the data entered. Hints: The standard deviation or of a finite data set x1, x2, ...,xn is defined by the following formula, u is the mean (X x where Au Sample input/output: Enter integer values for an Array of size 6 10 20 30 40 50 60 Your entered numbers are C 10 20 30 40 50 60 1 Mean is 35 SD is 17.0783 rocess returned 0 X0x0 execution time 8.720 s ress any key to continue. ter integer values for an Array of size 6 2 5 23 55 26 78 Your entered numbers are C 12 5 23 55 26 78 1 Mean is 33.1667 SD is 25.4389 rocess returned 0 (0x0> execution time 16.671 s ress any key to continue.Explanation / Answer
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
//Function Prototype
double mean(double[] , int size);
double standardDev(double[] , int size, double mean);
// Start of Main
int main () {
//Variables
int arraySize = 50;
double number = [50];
// Prompt the user about the program
cout << "This program will help the user to get the value of mean and standard deviation from 50 different numbers. " << endl;
cout << "Please follow the instruction, and enther the correct value." << endl;
cout << endl;
cout << endl;
// Input the numbers
for (int i=0; i<50; i++) {
cout << "Enter 50 different numbers : ";
cin>>n[i];
}
// Call the function
mean = (number, size);
standardDev = (number, size, mean);
// Output
cout << "The value of the mean: " << mean << endl;
cout << "The value of the standard deviation: " << standardDev << endl;
return 0;
}
// Function Definition
double mean (double number[], int size) {
double s1 = -999.99;
for ( int i = 0; i < arraySize; i++ ) {
s1 += n[i];
}
m=s1/50;
return m;
}
double standardDev (double number[], int size, double m) {
double standardDev;
double s2 = -999.99;
for ( int i = 0; i < size; i++ ) {
s2 += pow((n[i]-m),2);
}
standardDev= sqrt(s2/(size-1));
return standardDev;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.