Question
C++ 1. Write the function sum() that receives two parameters; a double type array and an integer type parameter representing the size of the array.
C++
1. Write the function sum() that receives two parameters; a double type array and an integer type parameter representing the size of the array. The function returns the sum of the elements in the array.
2. Write the function average() that receives two parameters; a double type array and an integer type parameter representing the size of the array. This function calculates the average of the numbers in the array and returns this average. The function average() must make a call to the function sum() in part (a) to obtain the sum of the elements used in calculating the average.
3. Write a main function that initializes and array of double type using random integers between 1 and 100. You can decide on the size of the array, perhaps a size between 10 to 20 elements. Display the numbers generated then call the function average() to receive the value of the average, which is then printed.
4 Rewrite the function average in part (b) average2() but make the return type of the function asvoid and use a reference parameter to communicate/return the calculated average to the man() function. ( hint: instead of two parameters the function average2() must have three parameters with some minor adjustments) [no need to make a call to this function, just write it to demonstrate the use of reference parameters.]
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