Question: Complete this program, by adding your mag( ) function from above, and add another function rect2polar (and prototype) that returns the polar form of a

Complete this program, by adding your mag( ) function from above, and add another function rect2polar (and prototype) that returns the polar form of a rectangular coordinate pair. The data type of the inputs, x, y should be double, as should the data type of the outputs r and theta. Since you already have a function which gets the magnitude of a vector, your rect2polar(...) function can call it to get half the job done. The commented code (which you'll need to un-comment) shows how your function should be called. Name your program pass_by_ref.cpp .

Reminder: The rectangular-to-polar function should take two arguments as input (x, y) and return two values (r, ) where:

r = mag (x,y)

= atan2(y,x)

note: rectangular coordinate (1,1) is equivalent to polar coordinate (2, PI/4); (-2, -2) should give you (8, -3PI/4)

note 2: since your function returns its two values through the reference parameters, the return type of the function should be void .

program:

#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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!