/*write a c++ program to create a class currency containing rupees and paisa as data members.
write a necessary emeber functionusing operator overloading for the
following.
1.currency(long int rup=0,int paisa=0)
2.currency &operaotr +=(currency &)to add one currency to another
3.currency & operator -=(currency &) to substract one currency from another
accept rupees & paisa from user and display it.
*/
#include<iostream.h>
#include<conio.h>
class currency
{
int r,p;
public:currency(long int rs=0,int paisa=0)
{
r=rs;
p=paisa;
}
currency & operator +=(currency &);
currency & operator -=(currency &);
};
currency & currency :: operator +=(currency &c2)
{
int a,b;
a=r+c2.r;
b=p+c2.p;
if(b>=100)
{
b=b-100;
a=a+1;
}
cout<<"\naddition of two currencyis:-";
cout<<"\nrupees:-"<<a;
cout<<"\npaisa:-"<<b;
return *this;
}
currency & currency:: operator -=(currency &c2)
{
int a,b;
a=r-c2.r;
b=p-c2.p;
cout<<"\nsubstraction of two currencyis:-";
cout<<"\nrupees:-"<<a;
cout<<"\npaisa:-"<<b;
return *this;
}
int main()
{
int rs,paisa;
clrscr();
cout<<"\n\t\taccept two currency \n\n";
cout<<"\nenter rupees:-";
cin>>rs;
cout<<"enter paisa";
cin>>paisa;
currency c1(rs,paisa);
cout<<"\nenter rupees:-";
cin>>rs;
cout<<"enter paisa";
cin>>paisa;
currency c2(rs,paisa);
c1+=c2;
c1-=c2;
getch();
return 0;
}
/*
accept two currency
enter rupees:-12
enter paisa34
enter rupees:-45
enter paisa34
addition of two currencyis:-
rupees:-57
paisa:-68
substraction of two currencyis:-
rupees:--33
paisa:-0
*/
write a necessary emeber functionusing operator overloading for the
following.
1.currency(long int rup=0,int paisa=0)
2.currency &operaotr +=(currency &)to add one currency to another
3.currency & operator -=(currency &) to substract one currency from another
accept rupees & paisa from user and display it.
*/
#include<iostream.h>
#include<conio.h>
class currency
{
int r,p;
public:currency(long int rs=0,int paisa=0)
{
r=rs;
p=paisa;
}
currency & operator +=(currency &);
currency & operator -=(currency &);
};
currency & currency :: operator +=(currency &c2)
{
int a,b;
a=r+c2.r;
b=p+c2.p;
if(b>=100)
{
b=b-100;
a=a+1;
}
cout<<"\naddition of two currencyis:-";
cout<<"\nrupees:-"<<a;
cout<<"\npaisa:-"<<b;
return *this;
}
currency & currency:: operator -=(currency &c2)
{
int a,b;
a=r-c2.r;
b=p-c2.p;
cout<<"\nsubstraction of two currencyis:-";
cout<<"\nrupees:-"<<a;
cout<<"\npaisa:-"<<b;
return *this;
}
int main()
{
int rs,paisa;
clrscr();
cout<<"\n\t\taccept two currency \n\n";
cout<<"\nenter rupees:-";
cin>>rs;
cout<<"enter paisa";
cin>>paisa;
currency c1(rs,paisa);
cout<<"\nenter rupees:-";
cin>>rs;
cout<<"enter paisa";
cin>>paisa;
currency c2(rs,paisa);
c1+=c2;
c1-=c2;
getch();
return 0;
}
/*
accept two currency
enter rupees:-12
enter paisa34
enter rupees:-45
enter paisa34
addition of two currencyis:-
rupees:-57
paisa:-68
substraction of two currencyis:-
rupees:--33
paisa:-0
*/
No comments:
Post a Comment