Lab 4 - Functions That Return a Value

Due: Midnight on the day of the lab

For this lab, you will be expanding on the function example given in class. The example given in class computes the average for 3 doubles. You can find the source code here: example.cpp. To copy the example to your directory with the following command:

cp /home/fac/melissa/public_html/cs221-f09/example.cpp lab4.cpp
Alternatively, you can copy and paste the example like you did in Lab 1.

You will be expanding this code by adding a second function that will compute the standard deviation of the 3 doubles. The standard deviation is calculated using the following formula:

deviation = sqrt( ((num1 - avg)2 + (num2 - avg)2 + (num3 - avg)2) / 2)

where avg is the result of calling average(num1, num2, num3).

You will need to do the following tasks:

  1. Create a function prototype for the standard deviation function and place the prototype above main().
  2. Create the function body for standard deviation, which will perform the above calculation, below the function body for average.
  3. Add a new cout in main() which will say "The standard deviation is " and then call your standard deviation function.
Email me your lab4.cpp file when you have finished these tasks.