C and C++

Program to convert cartesian co-ordinates into polar co-ordinates

Program to convert cartesian co-ordinates into polar co-ordinates
#include<iostream.h>
#include<math.h>
class rect
{
private:
float x, y, r, t;
public:
rect();
void polar();
void disp();
};
rect::rect()
{
cout<<"\n Enter x cordinate: "; cin>>x;
cout<<"\n Enter the y cordinate: "; cin>>y;
}
void rect::polar()
{
r = sqrt(x*x+y*y);
if(y<0)
{
if(x<0) { t = 180+tan(y/x)*180/3.14159265; } else t = tan(y/x)*180/3/14159265; } if(x>0 && y>0)
t = tan(y/x)*180/3.14159265;
cout<<"\n The polar form of ("<<x<<","<<y<<") is: ("<<r<<","<<t<<")";
}
void main()
{
float p;
rect a;
a.polar();
cout<<endl;

}

[wp_ad_camp_1]

OUTPUT
Enter x cordinate: 5
Enter the y cordinate: 4
The polar form of(5,4) is: (6.403124, 58.993942)

Leave a comment

Your email address will not be published. Required fields are marked *