Question
Assg 01: Review of Functions and Arrays COSC 2336 Data Structures Objectives Practice using predefined functions Review and practice writing user defined functions Review of
Assg 01: Review of Functions and Arrays
COSC 2336 Data Structures
Objectives Practice using predefined functions
Review and practice writing user defined functions
Review of arrays in C++
Practice passing arrays into functions Description
In this programming assignment you will write a program that will take an array of integers, and calculate the mean (average) and standard deviation of the numbers. If the numbers in the array are int n = 5; int x[] = {5, 3, 8, 2, 1}; Then to calculate the mean, we use the formula: x = 1 n nX1 i=0 xi where x represents the calculated mean, and n is the total number of values in the array x. In other words, the mean is simply the sum of the values divided by the total number of values (n), or x = x0 + x1 + x2 + x3 + x4 n = 5 + 3 + 8 + 2 + 1 5 = 3.8 Likewise, the formula for calculating the standard deviation of a set of values is given by: 1 s = vuut 1 n nX1 i=0 (xi x) 2 Here you should notice that x is the calculated mean of the values in the x array we just showed previously. In english, the standard deviation is shte sum of the square of the differences of each value from the mean. This sum of the squared differences is again divided by n the total number of values, then we take the square root of this whole calculation to get the final standard deviation. So for our example x array, the standard deviation would be calculated as s = r 1 n (x0 x) 2 + (x1 x) 2 + (x2 x) 2 + (x3 x) 2 + (x4 x) 2 = r 1 5 (5 3.8)2 + (3 3.8)2 + (8 3.8)2 + (2 3.8)2 + (1 3.8)2 2.4819 You will be given a starting template for this assignment. For this assignment you are to perform the following tasks. 1. Implement a function named calculateMean(). This function takes two parameters, an integer indicating the size of the array of values (n), and an array of integers. This function will return a value of type double. The functions should calculate the mean for any array of any sized passed in to it, as described above. 2. Implement a second function named calculateStandardDeviation(). This function takes the same two parameters, the size of the array of values (n) and an array of integers. This function will also return a double result. The function will calculate and return the standard deviation of any array of integers of any size passed to it. Some further requirements of this function. You must demonstrate the use of predefined functions from such as the pow() and sqrt() functions. Also, you must call the calculateMean() function from this function, e.g. do not repeat the calculation of the mean value, but reuse your previous function to do this work to obtain x. 2 Here is the correct output you get from your program if you correctly implement the two functions and use the array given to you in the starting template for this assignment: The calculated mean is: 5.6363636 The calculated standard deviation is: 2.6206428 The starting template you are given will compile. There are some lines of code commented out that call the functions you are supposed to write. You should uncomment those lines of code and write the functions so that you get exactly this given output from your program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started