Write a function named ComputeStats( ) that takes four arguments and returns voi
ID: 3628387 • Letter: W
Question
Write a function named ComputeStats( ) that takes four arguments and returns void.
The first two arguments are an array of integers and the size of the array. The array holds the data for which the function will compute the average and the standard deviation. The next two arguments are reference arguments which return the computed average and standard deviation to the calling function, main().
The standard deviation is defined to be the square root of the average of the values: (si a) , where a is the average of the values in the array and the si are the individual values.
Note: The average of { 2, 6, 8, 10, 15 } is 8.2 and the standard deviation is 4.308
Write a complete program that declares an int pointer and an int in main(). main() will make three function calls. main() calls a void function called GetArrayAlloc1() that interacts with the user. main() then fills the array with numbers (random number generator) and displays them. The allocated memory is then deleted. main() then calls a second void function, GetArrayAlloc2() that also interacts with the user. main() fills this array with numbers, displays them, then deallocates the memory. Finally, main()calls a value-returning function, GetArrayAlloc3() that again interacts with the user. main() fills this array with numbers and displays them, then deallocates the memory and ends.
void GetArrayAlloc1( )
This function takes two parameters, an int pointer reference and an int reference. The function asks the user what size array he/she would like (must be a positive int, size >= 1). An array of ints is allocated off the heap using the new function. The array is sent back to main() using the int pointer reference (first) parameter. The size of the array is sent to main() using the int reference (second) parameter.
void GetArrayAlloc2( )
This function takes two parameters, an int pointer pointer and an int reference. The function asks the user what size array he/she would like (size >= 1). An array of ints is
allocated off the heap. The array is sent back to main() using the int pointer pointer (first) parameter. The size of the array is sent to main() using the int reference (second) parameter.
int* GetArrayAlloc3( )
This function takes one parameter, an int reference only. The function asks the user what size array he/she would like (size >= 1). An array of ints is allocated off the heap using the new function. The size of the array is sent
*Whenever it says to fill an array with ints, use a random number generator, for example: srand(time(0)); rnd = 1 + rand() % 10;
Explanation / Answer
# include # include # include ComputeStats(int* A,int size,float* avg, float* dev) { int i; float sum=0.0; for(i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.