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

class InCurrency
{
	private:
	int rupees;
	int paisa;
	public:
	void display()
	{
		cout<< "Rupees = "<<rupees<<endl;
		cout<<"Paisa = "<<paisa<<endl;
	}
	int &amp; get_rupees()
	{
		return 	rupees;
	}
	int &amp; get_paisa()
	{
		return paisa;
	}
};

class UsCurrency
{
	private:
	int dollars;
	int cents;
	public:
	UsCurrency()
	{
		dollars=5;
		cents=30;
	}
	void display()
	{
		cout<< "Dollars = "<<dollars<<endl;
		cout<<"Cetns= "<<cents<<endl;
	}
	int &amp; get_dollar()
	{
		return 	dollars;
	}
	int &amp; get_cent()
	{
		return cents;
	}
	operator InCurrency ()
	{
		InCurrency temp;
		temp.get_rupees()=dollars;
		temp.get_paisa()=cents;
		return temp;
	}
};


void main()
{
	clrscr();
	InCurrency amount;
	UsCurrency total;
	amount=total;
	amount.display();
	getch();
}

Type Conversion in CPP – Conversion from one Class types to another class type

Leave a Reply

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