Lab 6 - May 2

  1. From the book, programming project 5.4, page 294:
    Write a function that computes the average and standard deviation of four scores. The standard deviation is defined to be the square root of the average of the four values: (si - a)2 where a is the average of the four scores s1, s2, s3, and s4. The function will have six parameters and will call two other functions. Embed the function in a driver program that allows you to test the function again and again until you tell the program you are finished.
    The book is a bit fuzzy on the definition of the standard deviation. You compute (si - a)2 for each of the four values and sum the results. Then take the square root of the sum divided by 4 (the sample size) to get the standard deviation estimate for that sample. See this Wikipedia page for the full equation and an example of estimating standard deviation from a sample. The "two functions" mentioned in the book definition are functions to compute the average of four samples and the standard deviation of four samples respectively.
  2. Copy your program from part 1. Add debugging statements to print out the four scores and any internal values in the function (such as the loop number and current sum if using a loop to compute the average and/or standard deviation) using #ifdef and #endif to your average and standard deviation functions. Make sure to also include the #define at the top of the program for the symbolic name used in the #ifdef. Recall the example from class for the retail price case study was:
    // Put at top of program after #include and using namespace
    #define DEBUG_ME
    
    // Put in program when you need a debug statement
    #ifdef DEBUG_ME
        printf("wholesale=%.2f days=%d retail=%.2f\n",
               wholesale_cost, shelf_time, retail_price);
    #endif /* DEBUG_ME */
    
Email your files to my Helios account.