Question

In: Computer Science

Write a program that takes, as input, five numbers and outputs the mean (average) and standard...

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₁, x₂, x₃, x₄, and x₅, then the mean is:

x = (x₁+ x₂+ x₃+ x₄+x₅)/5

and the standard deviation is:

s = √(((x₁-x)²+(x₂-x)²+(x₃-x)²+(x₄-x)²+(x₅-x)²)/5)

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.

Format your output with setprecision(2) to ensure the proper number of decimals for testing!

Solutions

Expert Solution

Code:

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
float mean(float x1,float x2,float x3,float x4,float x5)
{
   /*In this function we calculate the mean*/
   float x;
   x=(x1+x2+x3+x4+x5)/5;
   /*Here we calcuate the mean*/
   return x;
   /*here we return the mean*/
  
}
float deviation(float x1,float x2,float x3,float x4,float x5,float x)
{
   /*This function calculate the standard deviation*/
   float s;
   s=sqrt( (pow(x1-x,2)+pow(x2-x,2)+pow(x3-x,2)+pow(x4-x,2)+pow(x5-x,2))/5 );
   /*Calculating standard deviation*/
   return s;/*returning the standard deviation*/
}
int main()
{
   float x1,x2,x3,x4,x5,x,s;
   cout<<"Enter 5 numbers: "<<endl;
   cin>>x1;
   cin>>x2;
   cin>>x3;
   cin>>x4;
   cin>>x5;/*Reading 5 numbers form the user*/
   x=mean(x1,x2,x3,x4,x5);/*Here we get mean from the mean function*/
   s=deviation(x1,x2,x3,x4,x5,x);/*Here we get standard deviation from the deviation function*/
   cout<<"Mean: "<<setprecision(2)<<x<<endl;
   cout<<"Standard Deviation: "<<setprecision(2)<<s<<endl;  
   /*Here we print the result*/
}

output:

Indentation:


Related Solutions

Write a program that takes a date as input and outputs the date's season. The input...
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
Write a program in python that takes a date as input and outputs the date's season....
Write a program in python that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June...
Write a JavaScript program that computes the average of a collection of numbers and then outputs...
Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write a program that takes its input from a file of number type double and outputs...
Write a program that takes its input from a file of number type double and outputs the average of the numbers in the file to the screen. The file contains nothing but numbers of the type double separated by blanks and/ or line breaks. If this is being done as a class assignment, obtain the file name from your instructor. File name: pr01hw05input.txt 78.0 87.5 98.1 101.0 4.3 17.2 78.0 14.5 29.6 10.2 14.2 60.7 78.3 89.3 29.1 102.3 54.1...
in Java, write a program that takes an input of 4 numbers and splits them into...
in Java, write a program that takes an input of 4 numbers and splits them into 4 separate lines. EXAMPLE: so if input is 1994 the output should be 1 9 9 4
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT