Professional Documents
Culture Documents
h>
using namespace std;
#define pi 3.14
class polarform
{
private:
float deg, rad, x, y , r;
public:
polarform()
{
cout<<"Enter the magnitude : "<<endl;
cin>>r;
cout<<"Enter the angle : "<<endl;
cin>>deg;
}
void convert()
{
rad = deg * pi / 180;
x = r*cos(rad);
y = r*sin(rad);
}
void print()
{
cout << "The x coordinate is "<<x<< endl;
cout <<"The y coordinate is "<<y << endl;
}
};
class rectangle
{
private:
float deg, rad, x, y, r;
public:
rectangle()
{
cout << "Enter the x coordinate : "<<endl;
cin >> x;
cout << "Enter the y coordinate : "<<endl;
cin >> y;
}
void convert()
{
rad = atan(y/x);
deg = rad*180/pi;
r = sqrt(x*x + y*y);
}
void print()
{
cout <<"The magnitude is "<< r << endl;
cout <<"The angle is "<< deg <<"degrees"<< endl;
}
};
int main()
{
int opt;
cout << "1 polar to rectangle conversion\n2 rectangle to polar conversion\
nenter your choice : "<<endl;
cin>>opt;
switch(opt)
{
case 1:
{
polarform a;
a.convert();
a.print();
}
break;
case 2:
{
rectangle b;
b.convert();
b.print();
}
break;
default:
cout<< "ENTER PROPER CHOICE"<<endl;
break;
}
getchar();
}