C++ Programming Blog

 
 
 
//Three steps for Polar cordinates
//1)convert points to rectangular cordinates
//2)Addition of Points
//3)Converting Back to Polar cordinates

#include <iostream.h>
#include <math.h>
#include <conio.h>

class polar
{
  double radius;
  double angle;

  double getx()
    {return radius*cos(angle);} //These two function
  double gety()                 //convert this polar objects
    {return radius*sin(angle);} //into x and y rectangular coords

 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);   //converts x and y to
    double a=atan(y/x);         //Polar co-ordinate.
    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();
}

    Related Post:
  1. Double Linked List-C++

  2. Program of Sutherland Hodgemann Algorithm for Polygon clipping

  3. Program to show the use of Bitwise Operator Right Shift ( &gt;&gt; )

  4. Program to draw a line using Parametric equations

  5. Program to estimate the value of Third Derivative of the function at the given points from the given data using Central Difference Formula of order 2

  6. Program to estimate the value of First Derivative of the function at the given points from the given data using Central Difference Formula

  7. Program to construct Newtons Divided Difference Interpolation Formula from the given distinct data points and estimate the value of the function

  8. Program to illustrate unary operator(decrement operator) overloading with return type

  9. Program that uses this DFA and validates whether an entered string is valid integer or not.

  10. Program to find number of days b/w two given dates

  11. Stacks code in C++

  12. CREATING A LIST OF THE BOOKS AND THEIR DETAILS AND ACCEPTING DETAILS FROM THE CUSTOMER AND SEARCHING THE BOOKS

  13. Program to illustrate an example of Polymorphism ( Pure Virtual functions ).

  14. Program to read a Linear System of Equations,then evaluate it by using Jacobis Itrative Method and show the result

  15. Program of addition and subtraction of large numbers

  16. Program of reflection on any line

  17. Program to show the use of Bitwise Operator Left Shift ( &lt;&lt; )

  18. Program of cohen sutherland Line clipping Algorithm

  19. Program to find largest integer among the three and display it using function with no return type

  20. Program to determine whether the given function is a Cubic Spline or not

 
 
Didn't find what you were looking for? Find more on Program to convert points to rectangle coordinates and polar coordinates