Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program Requirements: Part 1: Polar Rectangular Conversation A location (point)

ID: 3789312 • Letter: P

Question

Program Requirements: Part 1: Polar Rectangular Conversation A location (point) in the two-dimensional Cartesian Coordinate System can be represented in two ways, by its Polar Coordinates or its Rectangular Coordinates. In the Polar Coordinate representation, the location is in the form M 0, where M is the distance from the origin to the point, and e is the angle measured from the X-axis to the point. In the Rectangular Coordinate representation, the location is in the form C. Y) where X and Y are the horizontal and vertical distances from their respective axes (X, Y) M To convert a location from the Polar Coordinates to the Rectangular Coordinates M cos (0) Y M sin (0) To convert a location from the Rectangular Coordinates to the Polar Coordinates. X2 Y 0 tan

Explanation / Answer

#include <math.h>   //library for trignometric functions used
#include <stdio.h>
int main()
{
double a,b,x,y,m,ang;
char c;
cout<<"Enter The coordinates Followed By R/r or P/p :";
cin>>a>>b>>c;     //reading the coordinates and character following them
if(c='r'||c='R') //check whether to see the character indicate rectangular coordinates
{
x=a;
y=b;

//calculate polar coordinates
m=sqrt((x*x)+(y*y));
ang=atan(y/x);

//print the cooordinates
cout<<"Rectangular ("<<x<<","<<y<<")";
cout<<"polar coordinates ("<<m<<" & "<<ang<< ")";

}
else if(c='p' ||c='P') //check if the character represent polar coordinates
{
m=a;
ang=b;

//calculate the rectangular coordinates
x=m*cos(ang);
y=m*sin(ang);

//print the coordinates
cout<<"Rectangular ("<<x<<","<<y<<")";
cout<<"polar coordinates ("<<m<<" & "<<ang<< ")";
}
else   //if the inpuut format mismatch print the message to user
cout<<"Illegal input format";
cout<<" Press any key to continue . . .";

//to read input character from user to continue
cin>>c;
return (0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote