WAP USING OPERATOR OVERLOADING TO ENTER RECTANGULAR CO-ORDINATES AND CONVERT THEM INTO POLAR CO-ORDINATES & VICE-VERSA
#include<conio.h>
#include<iostream.h>
#include<math.h>
class rec;
class polar
{
float rad,ang;
public:
polar() //without default constructor they is an error message
{ //couldnot find a match for polar::polar()
}
polar(float r,float a)
{
rad=r;
ang=a;
}
float getr()
{
return(rad);
}
float geta()
{
return(ang);
}
void disp()
{
cout<<"\n\nRadius::"<<rad<<endl
<<"Angle::"<<ang<<endl;
}
polar(rec r);
};
class rec
{
float x,y;
public:
rec()
{
}
rec(float xx,float yy)
{
x=xx;
y=yy;
}
float getx()
{
return(x);
}
float gety()
{
return(y);
}
void disp()
{
cout<<"(x,y)="<<x<<","<<y;
}
rec(polar p)
{
x=p.getr()*cos(p.geta());
y=p.getr()*sin(p.geta());
}
};
polar::polar(rec r1)
{
float x,y;
x=r1.getx();
y=r1.gety();
rad=sqrt(x*x+y*y);
ang=atan(y/x);
}
void main()
{
clrscr();
int a,b;
cout<<"Enter the rectangular co-ordinates i.e, x & y::";
cin>>a>>b;
rec r(a,b);
polar p;
p=r;
cout<<"\n\nConversion from rectangular to polar::"<<endl;
p.disp();
cout<<"\n\nEnter the Polar co-ordinates of radius & angle::";
cin>>a>>b;
polar p1(a,b);
rec r1;
r1=p1;
cout<<"\n\nConversion Polar to rectangular::"<<endl;
r1.disp();
getch();
}
#include<conio.h>
#include<iostream.h>
#include<math.h>
class rec;
class polar
{
float rad,ang;
public:
polar() //without default constructor they is an error message
{ //couldnot find a match for polar::polar()
}
polar(float r,float a)
{
rad=r;
ang=a;
}
float getr()
{
return(rad);
}
float geta()
{
return(ang);
}
void disp()
{
cout<<"\n\nRadius::"<<rad<<endl
<<"Angle::"<<ang<<endl;
}
polar(rec r);
};
class rec
{
float x,y;
public:
rec()
{
}
rec(float xx,float yy)
{
x=xx;
y=yy;
}
float getx()
{
return(x);
}
float gety()
{
return(y);
}
void disp()
{
cout<<"(x,y)="<<x<<","<<y;
}
rec(polar p)
{
x=p.getr()*cos(p.geta());
y=p.getr()*sin(p.geta());
}
};
polar::polar(rec r1)
{
float x,y;
x=r1.getx();
y=r1.gety();
rad=sqrt(x*x+y*y);
ang=atan(y/x);
}
void main()
{
clrscr();
int a,b;
cout<<"Enter the rectangular co-ordinates i.e, x & y::";
cin>>a>>b;
rec r(a,b);
polar p;
p=r;
cout<<"\n\nConversion from rectangular to polar::"<<endl;
p.disp();
cout<<"\n\nEnter the Polar co-ordinates of radius & angle::";
cin>>a>>b;
polar p1(a,b);
rec r1;
r1=p1;
cout<<"\n\nConversion Polar to rectangular::"<<endl;
r1.disp();
getch();
}

No comments:
Post a Comment