Question

In: Computer Science

In this lab, you will write a function that takes five (5) doubles as input and...

In this lab, you will write a function that takes five (5) doubles as input and passes back the mean (average) and the standard deviation. Your function should be named mean_std and it should return the mean (a double) and pass the standard deviation (also a double) back by reference.

The mean and standard deviation are a common calculation in statistics to express the range of "typical" values in a data set. This brief article explains how to calculate the standard deviation: http://www.mathsisfun.com/data/standard-deviation.html (Just the first part, up to where it says "But ... there is a small change with Sample Data".

Use the pow and sqrt functions from the cmath library in your function.

Passing in five separate numbers in five variables is annoying, but we haven't talked yet about passing around sets of numbers. That'll come in the next module.

Pay attention! You are passing back the two calculated values not printing them to the screen! There is no user input/output in this problem! Use what is given.

#include <iostream>
// including cmath to get access to pow and sqrt
#include <cmath>
using namespace std;

// put your function here, and name it mean_std


// main will be called when you are in "Develop" mode, so that you can put testing code here
// when you submit, unit tests will be run on your function, and main will be ignored
int main() {
   return 0;
}

Solutions

Expert Solution

Answer

#include <iostream>
#include <cmath>
using namespace std;
double mean_std(double num1,double num2,double num3,double num4,double num5,double &stdDev)
{
double avg=(num1+num2+num3+num4+num5)/5;
double variance = (pow((num1-avg),2)+pow((num2-avg),2)+pow((num3-avg),2)+pow((num4-avg),2)+pow((num5-avg),2))/5;
stdDev= sqrt(variance);
return avg;
}
int main()
{
double num1,num2,num3,num4,num5,mean,stdDeviation;
num1=1.1;
num2=2.2;
num3=3.3;
num4=4.4;
num5=5.5;
mean=mean_std(num1,num2,num3,num4,num5,stdDeviation);
  
//JUST TO SHOW OUTPUT
  
cout<<"\nNum 1 : "<<num1;
cout<<"\nNum 2 : "<<num2;
cout<<"\nNum 3 : "<<num3;
cout<<"\nNum 4 : "<<num4;
cout<<"\nNum 5 : "<<num5;
cout<<"\nMean of Numbers is : "<<mean;
cout<<"\nStandard Deviation of Numbers is : "<<stdDeviation;
return 0;
}

OUTPUT


Related Solutions

Draw a TM that takes as input a sequence of 1s and doubles the input
Draw a TM that takes as input a sequence of 1s and doubles the input
Write a function that takes a number as input, and returns the character A if the...
Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab...
write a function that takes as input the root of a general tree and returns a...
write a function that takes as input the root of a general tree and returns a binary tree generated by the conversion process illustrated in java
Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
(C++) Write a function that takes as an input parameter an integer that will represent the...
(C++) Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49. The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number...
In Java please: 5.23 LAB: Seasons Write a program that takes a date as input and...
In Java please: 5.23 LAB: Seasons 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:...
Write a function that takes a person’s first and last names as input and (a) uses...
Write a function that takes a person’s first and last names as input and (a) uses lists to return a list of the common letters in the first and last names (the intersection). (b) uses sets to return a set that is the intersection of the characters in the first and last names. (c) uses sets to return the set that is the symmetric difference between the first and last names. please write in python program
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
in c++ Write a function that takes a C string as an input parameter and reverses...
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Write an R function that conducts a normality test as follows: it takes as input a...
Write an R function that conducts a normality test as follows: it takes as input a data set, calculates a bootstrap confidence interval for the skewness, calculates a bootstrap confidence interval for the kurtosis, then sees if 0 is in the skewness interval and 3 is in the kurtosis interval. If so, your routine prints that the data is normally distributed, otherwise your routine should print that the data is not normally distributed. Test your routine on random data from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT