SOLUTION:
#include "stdafx.h"
#include "iostream"
#include "math.h"
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////
class polar
{
private:
float
radius, angle;
public:
polar(
) : radius(0.0), angle(0.0) {/*Empty
Body*/}
polar(float
r, float a) : radius(r), angle(a) {/*Empty
Body*/}
void
get_coordinates( )
{ cout << "Enter Radius
& Angle of the Point: "; cin
>> radius >> angle; }
void
put_coordinates( ) const
{ cout << "(" <<
radius << "," << angle << "\xF8)"; }
polar
operator + (polar) const;
};
//---------------------------------------------------------------------------------------polar polar::operator +
(polar p2) const
{
float x,
y;
polar temp;
x =
radius*cos(angle) + p2.radius*cos(p2.angle);
y =
radius*sin(angle) + p2.radius*sin(p2.angle);
temp.radius
= sqrt((x*x) + (y*y)); temp.angle =
atan(y/x);
return
temp;
}
/////////////////////////////////////////////////////////////////////////////////////////
void main( )
{
polar
pol1(20,45), pol2, pol3;
pol2.get_coordinates(
);
pol3 =
pol1 + pol2; cout
<< endl;
pol1.put_coordinates(
); cout << " + ";
pol2.put_coordinates(
); cout << " = ";
pol3.put_coordinates(
); cout << endl <<
endl;
system("pause");
}
OUTPUT:
0 comments: