//Conversion between objects of two different classes: Routine in destination object
# include < iostream.h >
# include < math.h >
# include < conio.h >
class polar
{
private:
double radius,angle;
public:
polar()
{ radius = 0.0; angle = 0.0;}
polar (double r, double a)
 { radius = r; angle = a; }
void display()
{ cout << "(" << radius << "," << angle << ")";}
double getr()
{ return radius; }
double geta()
{ return angle; }
	};
class rec {
private: 
double xco, yco;
public: rec() { xco = 0.0; yco= 0.0; }
rec(double x, double y)
{ xco = x; yco = y; }
void display(){ cout << "(" << xco << "," << yco << ")"; }
rec(polar p)
{
float r = p.getr();
float a = p.geta();
xco = r * cos(a);      yco = r * sin(a); }
};
void main()

{
clrscr();
rec rec1;
polar pol1 (10.0,0.785398);
rec1= pol1;
cout << "\n\n   pol1 = ";
pol1.display();
cout << "\n\n   rec1 = ";
rec1.display();
getch();
}
Click here to go back.

Our aim is to provide information to the knowledge seekers.


comments powered by Disqus


Footer1