#include <iostream.h>
#include <conio.h>

class Currency
{
	private:
	int rupees;
	int paisa;
	public:
	void setData(int x, int y)
	{
		rupees=x;
		paisa=y;
	}
	void getData()
	{
		cout<< " " << rupees<<" Rs."<< " " << paisa <<" paisa"<<endl;
	}
	Currency operator + (Currency &amp;c)
	{
		Currency temp;
		temp.rupees = rupees + c.rupees;
		temp.paisa = paisa + c.paisa;
		return temp;

	}

};

void main()
{
	clrscr();
	Currency c1,c2,c3;
	c1.setData(5,50);
	c2.setData(2,20);
	c3=c1+c2;
	c3.getData();
	getch();
}
Overloading Binary Operator + and – for Currency Class in CPP

Leave a Reply

Your email address will not be published. Required fields are marked *