In the above program, we created a class Distance that contains data members feet and inch. The Distance class contains three member functions SetDist(), PrintDist(), and AddDist().
The SetDist() function is used to set the values in the data member's feet and inch. The PrintDist() function is used to print the values of data members.
The AddDist() method is used to add the distance of the current object with the specified object and return the object that contains the addition of distance.
Here, we created two objects $d1 and $d2. Then add both distances using AddDist() function and assign the addition of distances in the object $d3.
Program/Source Code:
The source code to add two distances is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a class Distance that contains data members feet and inch. The Distance class contains three member functions SetDist(), PrintDist(), and AddDist().
The SetDist() function is used to set the values in the data member's feet and inch. The PrintDist() function is used to print the values of data members.
The AddDist() method is used to add the distance of the current object with the specified object and return the object that contains the addition of distance.
Here, we created two objects $d1 and $d2. Then add both distances using AddDist() function and assign the addition of distances in the object $d3.
need an explanation for this answer? contact us directly to get an explanation for this answer