Follow us on FB

Thursday, May 30, 2013

Operator overloading . adding angle and radius ( polar)

#include<iostream>
#include<math.h>
using namespace std;
class polar
{
    private:
        float radius;
        float angle;
    public:
        float getx()
        {
            return radius*cos(angle);
        }
        float gety()
        {
            return radius*sin(angle);
        }
        polar()
        {
            radius=0;
            angle=0;
        }
        polar(float r,float a)
        {
            radius=r;
            angle=a;
        }
        void show()
        {
            cout<<"radius : "<<radius<<endl;
            cout<<"angle : "<<angle<<endl;
        }
        polar operator +(polar p5)
        {
            float x=getx()+p5.getx();
            float y=gety()+p5.gety();
            float r=sqrt(x*x+y*y);
            float a=atan(y/x);
            return polar(r,a);
        }
   
};
int main()
{
    polar p1(5,30),p2(8,60);
    polar p3=p1+p2;
    p3.show();
    system("pause");
}

Unknown

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

0 comments:

Post a Comment

 

Copyright @ 2013 placeoflearn.