21. Create a class currency containing rupees and paise as data members. Write necessary member functions using operator overloading for the following: 1.currency (long int rup=0,int paise=0) 2.currency & operator += (currency &)(to add one currency to another) 3.currency & operator – = (currency &)(to subtract one currency from another) Accept Rupee & paise from user and display it.


#include<iostream.h>
#include<conio.h>
class currency
{
long int Rs;
int paise;
public:
currency()
{
Rs=0;
paise=0;
}
void get()
{
cout<<“\nEnter currency in Rs: “;
cin>>Rs;
cout<<“\nEnter currency in Paise: “;
cin>>paise;
}
void operator+=(currency &t)
{
Rs+=t.Rs;
paise+=t.paise;
cout<<“\n\nThe added currncy Rs: “<<Rs<<” “<<paise;
}
void operator-=(currency &t)
{
Rs-=t.Rs;
paise-=t.paise;
cout<<“\n\nThe Subtracted currncy Rs: “<<Rs<<” “<<paise;
}
void put()
{
cout<<Rs<<” “<<paise<<endl;
}
};
void main()
{
currency c1,c2;
clrscr();
c1.get();
c2.get();
cout<<“\n\tFirst currency Rs: “;
c1.put();
cout<<“\n\tSecond currncy Rs: “;
c2.put();
c1+=c2;
c1-=c2;
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s