Whats in this post?
- Background and Explanation of the code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
In the above program three objects r1, r2, r3 of type rational are created.Then setdata ( ) member function for r1 and r2 object is invoked to set the values of data members num and deno.The statement r3.add (r1, r2); on execution in main ( ) invokes member functions add ( ) through object r3 and pass two objects r1 and r2 as arguments.This function perform addition of passed rational number objects and the result is displayed using show ( ) member function which is invoked through r3 object.
Sum = 22/15