Search:

Submit Article

# Program to convert points to rectangle coordinates and polar coordinates

Posted By: Easy Tutor     Category: C++ Programming     Views: 29848

## Code for Program to convert points to rectangle coordinates and polar coordinates in C++ Programming

```/*www.DailyFreeCode.comDownload Projects, Sourcecodes, Tips and Tricks, Interview FAQs, Hotlinks and more....Logon to www.DailyFreeCode.com*///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 angle;

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

polar(float r,float a)
{
angle=a;
}

void display()
{
}

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 todouble 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();
}
```
Share:

 Easy Tutor author of Program to convert points to rectangle coordinates and polar coordinates is from United States. Easy Tutor says Hello Friends,I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] comI have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada. I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.Thanks,Happy Programming :) View All Articles

 David Sherwood from United States Comment on: Dec 09 There are a few minor problems with this code. Here is how I modified it slightly to run with Dev-C++5.11. Thank you very much.`/* www.DailyFreeCode.com Download Three steps for Polar cordinates: 1) Convert points to rectangular coordinates 2) Addition of Points 3) Converting Back to Polar coordinates*/#include #include using namespace std;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); }}; // ############## End of Class Declaration ##############int main(){ polar o1(10,2), o2(10,5), o3; o3 = o1 + o2; cout << "\no1 = "; o1.display(); cout << "\no2 = "; o2.display(); cout << "\no3 = "; o3.display();}`