public:
meters()
{
meter=0;
cms=0;
}
void getdata();
void display();
friend meters add(meters a,feet b) ;
friend feet add(feet b,meters a) ;
friend meters sub(meters a,feet b) ;
friend feet sub(feet b,meters a) ;
};
class feet
{
int foot,inches;
public:
feet()
{
foot=0;
inches=0;
}
void getdata();
void display();
friend meters add(meters a,feet b) ;
friend feet add(feet b,meters a) ;
friend meters sub(meters a,feet b) ;
friend feet sub(feet b,meters a) ;
};
void meters::getdata()
{
cout<<"\nenter the lenth in meters and centimeters\t";
cout<<"\nmeters\t";
cin>>meter;
cout<<"\ncentimeters\t";
cin>>cms;
}
void feet::getdata()
{
cout<<"\nenter the lenth in feet and inches\t";
cout<<"\nfeet\t";
cin>>foot;
cout<<"\ninches\t";
cin>>inches;
}
void meters::display()
{
cout<<"\nresult in meters and centimeters\t";
cout<<meter;
cout <<".";
cout<<cms;
}
void feet::display()
{
cout<<"\nresult in feet and inches\t";
cout<<foot;
cout <<".";
cout<<inches;
}
meters add(meters a,feet b)
{
int c;
meters d;
c=a.meter*100+a.cms+b.foot*30+b.inches*3;
d.meter=c/100;
d.cms=c%100;
return(d) ;
}
feet add(feet b,meters a)
{
int c;
feet d;
c=a.meter*100+a.cms+b.foot*30+b.inches*2;
d.foot=c/30;
d.inches=c%30;
return(d) ;
}
meters sub(meters a,feet b)
{
int c;
meters d;
c=a.meter*100+a.cms-b.foot*30-b.inches*3;
d.meter=c/100;
d.cms=c%100;
return(d) ;
}
feet sub(feet b,meters a)
{
int c;
feet d;
c=a.meter*100+a.cms-b.foot*30-b.inches*3;
d.foot=c/30;
d.inches=c%30;
return(d) ;
}
int main()
{
feet f,r;
meters m,n;
int o;
float x,y;
char d;
clrscr();
do
{
cout<<"\nenter your choice\t";
cout<<"\n1:to add two length and obtain result in meters \t";
cout<<"\n2:to add two length and obtain result in feet \t";
cout<<"\n3:to subtract two length and obtain result in meters \t";
cout<<"\n4:to subtract two length and obtain result in feet \t";
cin>>o;
switch(o)
{
case 1:
cout<<"\nenter the data\t";
m.getdata();
f.getdata();
n=add(m,f);
n.display();
break;
case 2:
cout<<"\nenter data\t";
m.getdata();
f.getdata();
r=add(f,m);
r.display();
break;
case 3:
cout<<"\nenter data\t";
m.getdata();
f.getdata();
n=sub(m,f);
n.display();
break;
case 4:
cout<<"\nenter data\t";
m.getdata();
f.getdata();
r=sub(f,m);
r.display();
break;
default:
cout<<"\nwrong choice\t";
break;
}
cout<<"\nif you want to continue please press .....y\t";
cin>>d;
}while(d=='y'||d=='Y');
return 0;
}
No comments:
Post a Comment