**Create a 'DISTANCE' class with :**

**a. feet and inches as data members**

**b. member function to input distance**

**c. member function to output distance**

**d. member function to add two distance objects**

**Write a main function to create objects of DISTANCE class. Input two distances and output the sum.**

**Program Code:***#include<iostream.h>*

*#include<conio.h>*

*class distance*

*{*

*int feet,inch;*

*public:*

*void getdistance();*

*void putdistance();*

*void adddistance(distance d1,distance d2);*

*};*

*void distance::getdistance()*

*{*

*cout<<"\nEnter the feet : ";*

*cin>>feet;*

*cout<<"\nEnter the inches :";*

*cin>>inch;*

*}*

*void distance::putdistance()*

*{*

*cout<<"\n\nfeet = "<<feet;*

*cout<<"\tinch = "<< inch;*

*}*

*void distance::adddistance(distance d1,distance d2)*

*{*

*inch=d1.inch+d2.inch;*

*feet=inch/12;*

*inch=inch%12;*

*feet=feet+d1.feet+d2.feet;*

*}*

*int main()*

*{*

*distance d1,d2,d3;*

*clrscr();*

*cout<< "\nDistance 1 \n";*

*d1.getdistance();*

*cout<< "\nDistance 2 \n";*

*d2.getdistance();*

*d3.adddistance(d1,d2);*

*cout<<"\nThe Sum Of two distance is : ";*

*d3.putdistance();*

*getch();*

*return(0);*

*}*

**The output of the above program is:***Distance 1*

*Enter the feet : 13*

*Enter the inches :11*

*Distance 2*

*Enter the feet : 11*

*Enter the inches :11*

*The Sum Of two distance is :*

*feet = 25 inch = 10*

**Thanks**

**Mukesh Rajput**
## Post A Comment:

## 0 comments: