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 SubDist().
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 SubDist() method is used to subtract a specified distance from the current object and return the object that contains the subtraction of distances.
Here, we created two objects $d1 and $d2. Then calculated the subtraction of distances using SubDist() function and assign the subtraction of distances in the object $d3.
Program/Source Code:
The source code to subtract one distance from another distance 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 SubDist().
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 SubDist() method is used to subtract a specified distance from the current object and return the object that contains the subtraction of distances.
Here, we created two objects $d1 and $d2. Then calculated the subtraction of distances using SubDist() function and assign the subtraction of distances in the object $d3.
need an explanation for this answer? contact us directly to get an explanation for this answer