I need some help please. I have calculus and I have to write a program convertin
ID: 3626586 • Letter: I
Question
I need some help please. I have calculus and I have to write a program converting from polar form to rectangular form and from rectangular to polar. The problem is I have no idea how to write a program. The assignment is:write a C++ program that will:
1. Take an input in Polar Form and change it to Rectangular Form.
2. Take an input in Rectangular Form and change it to Polar Form.
Place the program on a jump drive or CD. The program must be in a compiled executable form. Program should output the names of group members.
HINT
All calculations in programs use real numbers; therefore all angle arguments must be in radians. All degrees input must be changed to radians before calculations (1). All radian calculations must be changed to degrees before output (2).
To change degrees to radians: (degrees)(p)/ 180
To change radians to degrees: (radians)(180)/p
Explanation / Answer
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int k;
cout << "to convert polar to rectangular enter 1 :"<<endl;
cout << "to convert rectangular to polar enter 2 :"<<endl;
cin >>k;
if(k==1)
{
int mag;
double rad;
cout << "Enter Magnitude mag :";
cin >> mag;
cout << "Enter angle :";
cin >> rad;
cout << "Rectangular coordiantes are " <<endl;
rad = rad*3.14159/180;
cout << "x coordinate is " << static_cast<double>(mag)*cos(rad) <<endl;
cout << "y coordinate is " << static_cast<double>(mag)*sin(rad) <<endl;
}
else if(k==2)
{
double x,y;
cout << "Enter x cordiante :";
cin >> x;
cout << "Enter y coordinate :";
cin >> y;
cout << "polar coordiantes are " <<endl;
double magn = sqrt(x*x+y*y);
cout << "Magnitude is " << magn <<endl;
double angle = atan(y/x)*180/3.14159;
cout << "Angle is " << angle <<endl;
}
return 0;
}