Calculate Feet And Inches

Calculate Feet And Inches

Just open your c++ compiler Paste this code.

#include<iostream>

using namespace std;

class Distance
{
int fe;
float inch;
public:
Distance():fe(0),inch(0)
{
}
    Distance(int ft,float in):fe(ft),inch(in)
    {
    }
    void sub(int w,float x,int y,float z)
    {
    int f;
    float i;
    f = w-y;
    i = x-z;
        cout<<"distance 1 - distance 2 is = : ";
    cout<<f<<"'"<<i<<"''";
    }
   


};

int main()
{
Distance dist3;
int a,c;
float d,e;
cout<<"enter the 1st feet =";
cin>>a;
cout<<"enter the 1st inches =";
cin>>e;
cout<<"distance 2\n";
cout<<"enter the 2nd feet =";
cin>>c;
cout<<"enter the  2nd inches =";
cin>>d;

if(e>=12)
{
a++;
e-=12;
}
Distance dist1(a,e);
if(d>=12)
{
c++;
d-=12;
}
Distance dist2(c,d);
   if(a>c)
   {
 
   dist3.sub(a,e,c,d);
   }
   else
   {
    cout<<"2nd distance is greater";
   }
}

0 comments: