Lab 8 - Passing Arrays to Functions
NOTE: This lab will occur on Wednesday, November 4th. Tuesday, November 3rd
will be a lecture on these concepts.
In this lab, we will convert Question 2 from
Homework 4 to use functions instead of
doing everything in main(). If you did not complete Homework 4, refer to the
official solutions.
Three functions will be defined as follows:
- get_input() will have two arguments: an integer array and a by-reference
integer for the size. It is a void function. It will prompt the user for
the number of elements, verify that the number is between 2 and MAX_SIZE,
set the size to the number of elements and read the elements from the
keyboard into the array.
- calc_average() will have two arguments: an integer array and a by-value
integer for the size. It is a double function. It will return the average
of all the integers in the array.
- calc_stdev() will have two arguments: an integer array and a by-value
integer for the size. It is a double function. It will call calc_average()
to get the average and then calculate the standard deviation. It will then
return the standard deviation. You MUST call calc_average(). Do NOT pass
the average as another argument or recalculate the average.
Your main() function will declare the array (do not have a global array) and
the size variables. In main(), create a do-while driver loop that will call
get_input(). Then call calc_average() and print out the average that it returns.
Likewise, call calc_stdev() and print out the standard deviation. Then prompt
the user "Do you wish to enter another set of data (yes|no)? ". Use the
technique from Lab 7 to read their
response as a C-style string. Continue while the user responds "yes" or "Yes".
Email your assignment to Dr. Melissa Danforth on Sleipnir, as you have for the
other lab assignments. Do NOT email them to Dr. Marc Thomas.