Program To Add Two Distances By Returning An Object From A Function Using C++

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code


To copy code: Click View Source “View Source” on the right of this code snippet.

Background and Explanation of the code

The above program adds two distances entered by the user.For this we have created a class distance having member functions read ( ), show ( ) and add ( ) to input , display and add the distances respectively.The distance is specified in terms of feet and inches.


Enter feet and inches : 4   9

Enter feet and inches :  6   5

Addition is :    11 ‘   -2″