24.1 MONEY MATTER

In this section, we have four classes which are very similar in nature. The difference is mainly in the methods defined.

class Money

  { private:     long rupee, paise ;   public :     Money( long a, long b) ;     Money();     void show();  } ;

class Amount

    { private:      long rupee, paise ;    public:      Amount() ;      Amount(long p, long q) ;      void show() ;      friend Amount operator +( Amount a1 , Amount a2 );      Amount validate (Amount a);  } ;

Class amount is improvement over money. Normally, we need adding two amounts. Hence, an operator function is provided. While adding the value of Paisa may become 100 or more. Therefore, we need the method validate. Here, method validates and returns the corrected amount. ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.