#include<iostream.h>
#include<conio.h>
class db;
class dm
{
float mt;
float cm;
public:
dm()
{
// mt=0.0;// cm=0.0;
}
void getdata()
{
cout<<"**** ENTER THE MEASUREMENT IN METERS ****";
cout<<"\n\n METERS :";
cin>>mt;
cout<<"\n CENTIMETERS :";
cin>>cm;
int cms;
cms=int(cm); //converting float to intfloat diff;
diff=cm-float(cms); //finding the decimal value for roundoffif(diff>=0.5)
cms++;
cm=float(cms)/100; //converting cms to mts
mt=mt+cm; //adding those cms to mts
cout<<"\n THE MEASUREMENT ENTERD IN METERS IS :"<<mt;
}
void putdata() //for displaying the final output
{
cout<<"\n\n\nAFTER CONVERSION THE MEASUREMENT IN METERS IS :"<<mt;
getch();
}
friend dm sum(dm,db); //declaring friend func. for summation in mts.
friend db sum1(dm,db); //declaring friend func. for summation in fts.
};
class db
{
float ft;
floatin;
public:
db()
{
ft=0.0;
in=0.0;
}
void getdata()
{
cout<<"\n\n\n**** ENTER THE MEASUREMENT IN FEETS ****";
cout<<"\n FEETS :";
cin>>ft;
int fts;
fts=int(ft); //converting float to intfloat diff;
diff=ft-float(fts); //finding the decimal difference for roundoffif(diff>=0.5)
fts++;
cout<<"\n INCHES :";
cin>>in;
int inch;
inch=int(in); //converting float to int
diff=in-float(inch); //finding the dec. difference for roundoffif(diff>=0.5)
inch++;
ft=float(fts);
int rem;
rem=inch%12; //finding the remaining inches
inch=inch/12; //finding if inches can be converted to ft.in=float(inch);
ft=ft+in; //adding inches converted to feetin=float(rem)/10; //converting the diff to decimal
ft=ft+in; //adding the diff. in inches to ft.
cout<<"\n\n THE MEASUREMENT ENTERED IN FEET :"<<ft;
}
void putdata()
{
cout<<"\n\n\n AFTER CONVERSION THE MEASUREMENT IN FEET IS :"<<ft;
getch();
}
friend dm sum(dm,db);
friend db sum1(dm,db);
};
dm sum(dm d1,db d2)
{
dm a;
d2.ft=d2.ft*(1/3.281); //converting feet to mts
a.mt=d1.mt+d2.ft;
return a;
}
db sum1(dm d1,db d2)
{
db b;
d1.mt=d1.mt*3.281; //converting meters to feet
b.ft=d2.ft+d1.mt;
return b;
}
main()
{
clrscr();
dm d1,a;
db d2,b;
d1.getdata();
d2.getdata();
int ans;
cout<<"\n\n";
while(1)
{
cout<<"ENTER THE FORMAT YOU WANT YOUR ANSWER IN(1 FOR MT./2 FOR FT.):";
cin>>ans;
if(ans==1)
break;
elseif(ans==2)
break;
else
{
cout<<"\n INVALID CHOICE ";
continue;
}
}
if (ans==1)
{
a=sum(d1,d2);
a.putdata();
}
else
{
b=sum1(d1,d2);
b.putdata();
}
}