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

class Currency
{
	private:
	int rupees;
	int paisa;
	public:
	void  setData(int x, int y)
	{
		rupees=x;
		paisa=y;
	}
	friend	ostream &amp; operator << (ostream &amp;out, Currency &amp;);
	friend istream &amp; operator >> (istream &amp;in, Currency &amp;);

};
ostream &amp; operator << (ostream &amp;out, Currency &amp;c)
{
	out<<" Rs. "<<c.rupees<< " Paisa "<<c.paisa<<endl;
	return out;
}
istream &amp; operator >> (istream &amp;in, Currency &amp;c)
{
	in>> c.rupees >> c.paisa;
	return in;
}


void main()
{
	clrscr();
	Currency amount;
//	amount.setData(10,50);
	cin>>amount;  //extraction overloaded
	cout<<amount;                        //insertion operator overloeaded
	getch();

}
Overloading insertion (<<) and extraction (>>) operator in CPP

Leave a Reply

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