Comparison 2 (Feet And Inches)
Comparison 2 (Feet And Inches)
Just open your c++ compiler Paste this code.
#include<iostream>
using namespace std;
class Distance
{
int feet;
float inches;
public:
Distance():feet(0),inches(0)
{
}
Distance(int ft,float in):feet(ft),inches(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 feet =";
cin>>a;
cout<<"enter the inches =";
cin>>e;
cout<<"distance 2\n";
cout<<"enter the feet =";
cin>>c;
cout<<"enter the 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";
}
}
Just open your c++ compiler Paste this code.
#include<iostream>
using namespace std;
class Distance
{
int feet;
float inches;
public:
Distance():feet(0),inches(0)
{
}
Distance(int ft,float in):feet(ft),inches(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 feet =";
cin>>a;
cout<<"enter the inches =";
cin>>e;
cout<<"distance 2\n";
cout<<"enter the feet =";
cin>>c;
cout<<"enter the 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: