Write and run a program that has a function called polar_to_ rect () that conver
ID: 3670613 • Letter: W
Question
Write and run a program that has a function called polar_to_rect() that converts a polar vector to a rectangular vector. The arguments for this function should be the magnitude (mag) of the polar vector, the angle in degrees (ang) of the polar vector, the rectangular coordinate length of x and the rectangular coordinate length of y. ang and mag must be "passed by value" to this function while x and y must be "passed by reference" to the function. In main(), the values of mag and ang should be requested from the user. The function should then be called. Those values of ang and mag should be passed to the function by value when it is called. The values of x and y will be updated by the function and written into memory. "cout" the values of x and y IN MAIN(). On completion, ask the user if another conversion is wanted (use a "while" statement). The function should have a "void" return value. All variables should be of double data type. Use the sin() and cos() cmath functions to determine the values of x and y. Don't forget to convert degrees to radians when using these trigonometric functions. C++
Write and run a program that has a function called polar_to_rect() that converts a polar vector to a rectangular vector. The arguments for this function should be the magnitude (mag) of the polar vector, the angle in degrees (ang) of the polar vector, the rectangular coordinate length of x and the rectangular coordinate length of y. ang and mag must be "passed by value" to this function while x and y must be "passed by reference" to the function. In main(), the values of mag and ang should be requested from the user. The function should then be called. Those values of ang and mag should be passed to the function by value when it is called. The values of x and y will be updated by the function and written into memory. "cout" the values of x and y IN MAIN(). On completion, ask the user if another conversion is wanted (use a "while" statement). The function should have a "void" return value. All variables should be of double data type. Use the sin() and cos() cmath functions to determine the values of x and y. Don't forget to convert degrees to radians when using these trigonometric functions. C++
Write and run a program that has a function called polar_to_rect() that converts a polar vector to a rectangular vector. The arguments for this function should be the magnitude (mag) of the polar vector, the angle in degrees (ang) of the polar vector, the rectangular coordinate length of x and the rectangular coordinate length of y. ang and mag must be "passed by value" to this function while x and y must be "passed by reference" to the function. In main(), the values of mag and ang should be requested from the user. The function should then be called. Those values of ang and mag should be passed to the function by value when it is called. The values of x and y will be updated by the function and written into memory. "cout" the values of x and y IN MAIN(). On completion, ask the user if another conversion is wanted (use a "while" statement). The function should have a "void" return value. All variables should be of double data type. Use the sin() and cos() cmath functions to determine the values of x and y. Don't forget to convert degrees to radians when using these trigonometric functions. C++
Explanation / Answer
Code:
#include <iostream>
#include<cmath>
#define PI 3.14159265358979323846
using namespace std;
void polar_to_rect(double magnitude, double angle,double *x, double *y )
{
*x=magnitude*cos(angle*PI/180);
*y=magnitude*sin(angle*PI/180);
}
int main()
{
char c;
double magnitude,angle,x,y;
do{
cout<<"enter the magnetude"<<endl;
cin>>magnitude;
cout<<"enter the angle in digrees"<<endl;
cin>>angle;
polar_to_rect(magnitude,angle,&x,&y);
cout<<"the rectangular co-ordinates are ( "<<x<<" , "<<y<<" )"<<endl;
cout<<"do you want another convertion..? y/n"<<endl;
cin>>c;
}while(c=='y' || c=='Y');
return 0;
}
Output:
n
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.