Question
Complete this program: add two functions (& their prototypes) that return the maximum and minimum value of an array of x elements. The program should
Complete this program: add two functions (& their prototypes) that return the maximum and minimum value of an array of x elements. The program should ask the user for these x elements.
Hint: the functions will return a single integer value, and should have 2 parameters: the array (passed as a constant array), and the numbers of values in the array.
Question: do the min_element(...) and max_element(...) functions modify the arrays in any way? If not, then the array parameter (in both the function prototype and the function definition) should be declared "const" . While your functions will work just fine without the keyword const, it is better to use it here. That signals to readers of your code that the array will not be modified by the function, and would trigger a compiler error if you tried to modify the array inside the function. This is one of C++'s features that helps reduce human error. C++
PART B
Move the task of querying the user for the array values to a function query_for_array(...) .
Question: what should be the return type of this function? Question 2: Do you need the keyword const here?
PART C
Add a function array_average(int array, int length); that returns the average value of the elements in the array.
Then add another function array_stats(...) that returns the min, max and average of an array.
Useful hint: you already have functions to get the min, max and average. Your stats function can simply call them...no need to cut and paste to get the smaller jobs done! Question: what should be the return type of this function? (hint: with more than one piece of information to pass back, your function should use all reference parameters, and not pass anything back via the return statement.)
Reminder: be sure to put ampersands (&) in front of your parameter names to make them reference parameters!
C++
#include#include using namespace std; // for part a, put your function prototype for mag here! // for part b, put your function prototype for rec2polar here! //............................................................ int main(void) { double x = 0; double y = 0; double v=-6.0, w=8.0; double m; cout << "Please enter the X coordinate: "; cin >> x; cout << "Please enter the Y coordinate: "; cin >> y; m = mag(x,y); // you need to write this function! cout << "The magnitude of ( "<< x << " , "<< y <<" ) is: " << m << endl; m = mag(v,w); // now get the magnitude of vector (v,w) cout << "The magnitude of ( "<< v << " , "<< w <<" ) is: " << m << endl; /* // for part 1b, uncomment these lines and add a function to calculate // the polar form of (x,y); double r, theta; rect2polar(x,y,r,theta); cout << "the polar form of ( "<< x << " , "<< y <<" ) is: ( " << r << " , " << theta << " )"<
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