Part 1b: Another Function and Prototype See example 2 for examples that may help
ID: 3935884 • Letter: P
Question
Part 1b: Another Function and Prototype
See example 2 for examples that may help you solve this problem
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 (1.414, PI/4); (-2, -2) should give you (2.818, 5PI/4)
note 2: since your function returns its two values through the reference parameters, the return type of the function should be void .
Name your program pass_by_ref.cpp
===============================THE PROGRAM IS POSTED BELOW==============================
Explanation / Answer
;>
rect2polar(x,y,r,theta);
cout &xx;&xx; "the xxxxx xxxx xx ( "&xx;&xx; x &xx;&xx; " ,"&xx;&xx; y &xx;&xx;" ) xx: ( " << x << " , " <<theta &xx;&xx; " )"&xx;&xx;xxxx;xxxxxxxxxx(x,x,x,xxxxx);xxxx &xx;&xx; "xxx polar xxxx of ( "&xx;&xx; x << " ,"<< x &xx;&xx;" ) is: ( " &xx;&xx; x &xx;&xx; " , " &xx;&xx;xxxxx &xx;&xx; " )"<<endl;
return x;}xxxxxx mag(double x, xxxxxx y){xxxxxx sqrt(x*x + y*y);
}
double xxxxxxxxxx(xxxxxx x, xxxxxx y, xxxxxx&xxx; r, xxxxxx&xxx;xxxxx){xxxxx = xxxx(x/y) * xxx / PI; //PI xx a xxxxxxxx, atan xxxxxxx xxxxxxxxxx xxx return xx radians
r = xxx(x, y);//xxxxx is xxx in xxxxxxx}