Reference no: EM132164313
Using C++
Do not make use of any variables in your answers to this question.
Use recursive functions to cause repetition when needed. No loops
For this parts A to C you will be writing some functions that process arrays of positive ints. The arrays can be of any length, but will always have a value of -1 added as a sentinel to indicate the end of the data. The -1 is not part of the data to be processed, it just marks the end.
Here are two example arrays that your function might have to work on:
const int X[] = { 9, 5, 3, 7, 2, 4, 3, 4, -1 };
const int Y[] = { 1, 0, 2, 0, -1 };
You may always make use of previous answers You may always give your functions extra parameters if needed.
Part A. Write a function that can take any such array as its parameter, and print all the data it contains (not including the -1) on a single line.
For example, answera(X) should print 9 5 3 7 2 4 3 4
answera(Y) should print 1 0 2 0
Part B. Write a function that given such an array as its parameter, returns as its result the number of data items in the array.
For example,
the value of answerb(X) should be 8
the value of answerb(Y) should be 4
Part C. Write a function that given such an array as its parameter, calculates and prints the average of all the data items in the array
For example,
answerc(X) should print 4.675
answerc(Y) should print 0.75
Part D. Write a function that takes a double A and an int B as its parameters. It should calculate and return as its result the value of A to the power of B. Do not use logarithms.
For example, the value of answerd(3.0, 4) should be 81.0