Polar Coordinates Addition code example
Example: Polar Coordinates Addition
#include <iostream.h>
#include <math.h>
#include <conio.h>
class polar
{
double radius;
double angle;
double getx()
{return radius*cos(angle);}
double gety()
{return radius*sin(angle);}
public:
polar()
{radius=0.0;angle=0.0;}
polar(float r,float a)
{
radius=r;
angle=a;
}
void display()
{
cout<<\"(\"<<radius<<\", \"<<angle<<\")\";
}
polar operator + (polar o2)
{
double x=getx()+o2.getx();
double y=gety()+o2.gety();
double r=sqrt(x*x + y*y);
double a=atan(y/x);
return polar(r,a);
}
};
void main()
{
clrscr();
polar o1(10,2),o2(10,5),o3;
o3=o1+o2;
cout<<\"\\no1 =\";
o1.display();
cout<<\"\\no2 =\";
o2.display();
cout<<\"\\no3 =\";
o3.display();
getch();
}