Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete this program: add two functions (& their prototypes) that return the ma

ID: 3684850 • Letter: C

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 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++

Explanation / Answer

HI friend, Question and Code that you have posted are completely different.

I am confused whether i should answer according to question or Code.

Please clarify my doubt

Anyway, I have implemented functionality for Code

#include<iostream>
#include<cmath>

using namespace std;

//for part a, put your function prototype for mag here!
double mag(double, double);

// for part b, put your function prototype for rec2polar here!
void rec2polar(double x, double y, double& r, double& theta);
//............................................................

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;
  
rec2polar(x,y,r,theta);

cout << "the polar form of ( "<< x << " , "<< y <<" ) is: ( " << r << " , " << theta << " )"<<endl;

rec2polar(v,w,r,theta);

cout << "the polar form of ( "<< v << " , "<< w <<" ) is: ( " << r << " , " << theta << " )"<<endl;


return 0;
}


//.................put your mag function here...................
// be sure to add comments describing the inputs and outputs so a reader would
// know how to use it.
double mag(double x, double y){
  
   return sqrt(pow(x, 2) + pow(y, 2)); //return the magnitude (pythagoras)
}


//.................put your rect2polar function here...................
// be sure to add comments describing the inputs and outputs so a reader would
// know how to use it.
// taking r and theta as refrence variable
void rec2polar(double x, double y, double& r, double& theta){
  
   r = sqrt((pow(x,2))+(pow(y,2)));

theta = atan(y/x);
  
   theta = (theta*180)/3.141592654;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote