#include<iostream.h>
#include<conio.h>
class
distance
{
private :
int mts ;
int cms;
public :
void init (int a, int b)
{
mts=a; cms = b;
}
void get();
void put();
void add(distance, distance)
;
} ;
void
distance::get()
{
cout<<"enter two
distances in meter:";
cin>>mts>>cms;
}
void
distance :: put ( )
{
cout<<"\n"<<mts<<"
Meters "<<cms<<"centimeters";
}
void
distance :: add (distance dl, distance d2)
{
mts = dl.mts+d2.mts;
cms = dl.cms+d2.cms;
if (cms>100)
{
mts+=cms/100;
cms%=100;
}
}
void main ()
{
clrscr();
distance
ob1,ob2,ob3;
ob1.get();
ob2.init(5,85);
ob3.add(ob1,
ob2);
cout<<"The
two distances are..";
ob1.put ( )
;
cout<<"\nAnd";
ob2.put () ;
cout<<"\nSum
is ";
ob3. put ()
;
getch();
}
Out put
Enter a distance in meters and cms : 7
65
The two distances are:
7 Meters 65 Centimeters
And
5 Meters 85 Centimeters
Sum is
13 Meters 50 Centimeters.
No comments:
Post a Comment