### get equivalent polar coordinates

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#ifndef _POINTCLASS_H #define _POINTCLASS_H #define _POINTCLASSS_H #include using namespace std; class Point { private: double x; double y; public: Point(); Point(double anx, double ay); bool Equals(Point& otherPt); double GetX() const; double GetY() const; void SetX(double newX); void SetY(double newY); //void AddOffsetPoint(const Point& other); void Print(ostream& out) const; friend ostream& operator<<(ostream& out, const Point& pt); double Radius() const; double Theta() const; }; inline double Point::GetX() const { return x; } inline double Point::GetY() const { return y; } inline ostream& operator<<(ostream& out, const Point & pt) { pt.Print(out); return out; }``````

 ``123456789101112131415161718192021`` ``````#include "PointClass.h" #include Point::Point() { x = y = 0.0 ; } Point::Point(double anx, double ay) { x = anx; y = ay; } bool Point::Equals(Point& otherPt) { return (this->x==otherPt.x) && (this->y==otherPt.y); } void Point::SetX(double newX) { x = newX; } void Point::SetY(double newY) { y = newY; } void Point::Print(ostream& out) const { out << "[" << x << ", " << y << "]"; } ``````

don't know how to start to define Radius() and Theta()
can any body give some suggestion and sample coding for me?
If you just want to know how to calculate the radius and angle theta, it's pretty straightforward.

The radius can be found using Pythagoras' theorem
`sqrt(x*x + y*y);`

Theta can be determined using the function `atan2()`
http://www.cplusplus.com/reference/cmath/atan2/
@chervil.

i already did that and thanks you for your patiently teaching me

polar coordinates are written in the from (r, theta) were r is the radius and theta is the anti-clockwise angle for the positive x-axis.

here is this
 ``1234567891011121314`` ``````double Point::Radius() const{ return sqrt( x*x + y*y ); } double Point::Theta() const{ double PI = 3.142; double result = 0.00; result = atan2(y,x) * 180 / PI; } void Point::polarCoordinate(double radius , double theta ){ radius = Radius(); theta = Theta(); }``````

so currently did i correct?

so how should i actually create few points whose polar coordinates and invoke my new method already , my head confusing due to i done 2 algorithm multiplication today . sorry for it
Last edited on
Function `double Point::Theta()` should return a value.

I'm not sure what you want function `Point::polarCoordinate` to do? If you want to return the values of radius and theta, then pass them by reference.

Or are you trying to alter an existing point using the supplied values of radius and theta?
@chervil

i did not paste correctly
 ``123456`` ``````double Point::Theta() const{ double PI = 3.142; double result = 0.00; result = atan2(y,x) * 180 / PI; return result; }``````

because i don't really understand what is polar coordinate count out

here is the example link :
http://www.algebra.com/algebra/homework/Trigonometry-basics/Trigonometry-basics.faq.question.43941.html

 ``1234`` ``````void Point::polarCoordinate(double &radius , double &theta ){ radius = Radius(); theta = Theta(); }``````

Last edited on
can someone help me out
Can you please explain what is the exact question you have.
Add code to the PointClassDriver program to create a few points whose polar coordinates you would know and which then invokes your new method

not really know how to make it to showing out .
That's just asking you to try some data to test that your code works correctly. In function main() add a few points, for example
 ``123`` `````` Point a(5,5); Point b(1, sqrt(3.0)); Point c(3, -4);``````

Then call the `polarCoordinate()` method and output the resulting values of radius and theta.

The expected results for my suggested data is
a will have radius = 7.07106781186548 and theta = 45
b should have radius = 2 and theta = 60
and c has radius = 5 and theta = -53.130102354156

Of course the choice of data is up to you, these are just examples.
@chervil