#include <iostream>
using namespace std;
////////////////////////////////////////////////////////////////
class Distance //English Distance class
{
	private:
		const float MTF; //meters to feet
		int feet;
		float inches;
	public: //constructor (no args)
		Distance() : feet(0), inches(0.0), MTF(3.280833)
		{ } //constructor (two args)

		Distance(int ft, float in) : feet(ft), inches(in), MTF(3.280833)
		{ }
		
		Distance(float meters) : MTF(3.280833)
		{ //convert meters to Distance
			float fltfeet = MTF * meters; //convert to float feet
			feet = int(fltfeet);          //feet is integer part
			inches = 12*(fltfeet-feet);   //inches is what’s left
		} //constructor (two args)
		
		void getdist() //get length from user
		{
		cout <<"\nEnter feet: "; cin >> feet;
		cout <<"Enter inches: "; cin >> inches;
		}

		void showdist() const //display distance
		{  			cout << feet << " , " << inches ; }

		operator float() const          //conversion operator
		{                               //converts Distance to meters
			float fracfeet = inches/12; //convert the inches
			fracfeet += feet; //add the feet
			return fracfeet/MTF;                  //convert to meters
		}
		/*void operator =(float meters){
            float fltfeet = MTF * meters; 
            cout<<"1st operator ="<<endl;
            feet = int(fltfeet);          //feet is integer part
			inches = 12*(fltfeet-feet);        
        }*/
        void operator =(Distance d){
                 cout<<"2nd operator ="<<endl;
                 feet = d.feet;
                 inches = d.inches;
             }
};

main()
{
	float mtrs;
	Distance dist1 = 1; 
    Distance dist2(2);
	cout << "\ndist1 = "; dist1.showdist();
    dist1 = 2.5;
    dist1 = dist2;
    cout << "\ndist1 = "; dist1.showdist();
    cout<<endl;
    
    //convert meters to Distance
/*	cout << "\ndist1 = "; dist1.showdist();
   
	mtrs = dist1; //uses conversion operator
	//for Distance to meters
	cout << "\ndist1 = " << mtrs << " meters\n";
	
    Distance dist2(6, 7); //uses 2-arg constructor
	mtrs = dist2; //also uses conversion op
	cout << "\ndist2 = " << mtrs << " meters\n";
	// dist2 = mtrs; //error, = won’t convert
  
/*  int a;
	float f=10.54F;
	a=static_cast<int>f;
	cout<<"a = "<<a<<endl;
*/

	system("pause");
}
