//Conversion between objects of different classes: Routine in Source Object
# include < iostream.h >
# include < math.h >
#include < conio.h >
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 << ")";}
};	// end of rec class declaration
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 << ")";}
operator rec()
{
double x = radius * cos(angle);
double y = radius * sin (angle);
return rec(x,y);
}
}; 	// end of polar class declaration
void main()
{
clrscr();
rec rec1;
polar pol1 (10.0,0.785398);
rec1= pol1;
cout << "\n pol1 = ";
pol1.display();
cout << "\n recl = ";
rec1.display();
getch();
}
Click here to go back.

Our aim is to provide information to the knowledge seekers. 


comments powered by Disqus


Footer1