//Conversion from Object to Basic type
# include < iostream.h >
#include < conio.h >
const float MTF = 3.280833;
class distance
{
private: int feet; float inches;
public: distance()
       {feet = 0; inches = 0.0;}
       distance (int ft, float in)
       {feet = ft; inches = in;}
       distance(float meters)
       { float fltfeet = MTF * meters;
	 feet = int (fltfeet);
	 inches = 12 * (fltfeet - feet);
	 }

void showdist()
{ cout << feet << " feet " << " "<< inches <<  " inches " ;}
operator float ()
{ float f=inches/12;
 f= f+float (feet);
return f/MTF;
}
};
void main() {
distance dist1 = 2.35; //constructor used
clrscr();
cout << "\n\n distl = ";
dist1 .showdist();
distance dist2(5,10.25);
float meters = float(dist2);
//uses conversion function to convert
cout << "\n\n dist2 = " << meters << " meters ";
meters = dist1; //uses Conversion function
cout << "\n\n dist1 = " << meters << " meters ";
getch();
}
Click here to go back.

Our aim is to provide information to the knowledge seekers.


comments powered by Disqus






Footer1