Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 (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 .

The program is:

#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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions