Define currency class which contains rupees and paisa as data members. Write a friend function named AddCurrency ( ) which add 2 different Currency objects and returns a Currency object. Write parameterized constructor to initialize the values and use appropriate functions to get the details from the user and display it.
CODING:
#include<iostream.h>
#include<conio.h>
class currency
{
int r,p;
public:
currency(int x,int y){r=x;p=y;}
currency add(currency ob1);
void disp();
};
currency currency::add(currency ob1)
{
currency ob3(0,0);
ob3.r=ob1.r+r;
ob3.p=ob1.p+p;
if(ob3.p>=100)
{
ob3.r=ob3.r+1;
ob3.p=ob3.p-100;
}
return ob3;
}
void currency::disp()
{
cout<<"ADDITION:"<<r<<'.'<<p;
}
void main()
{
int a,b;
clrscr();
cout<<"Ruppes:";
cin>>a;
cout<<"Paisa :";
cin>>b;
currency ob1(a,b);
cout<<"Ruppes:";
cin>>a;
cout<<"Paisa :";
cin>>b;
currency ob2(a,b);
currency ob3(0,0);
ob3=ob1.add(ob2);
ob3.disp();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class currency
{
int r,p;
public:
currency(int x,int y){r=x;p=y;}
currency add(currency ob1);
void disp();
};
currency currency::add(currency ob1)
{
currency ob3(0,0);
ob3.r=ob1.r+r;
ob3.p=ob1.p+p;
if(ob3.p>=100)
{
ob3.r=ob3.r+1;
ob3.p=ob3.p-100;
}
return ob3;
}
void currency::disp()
{
cout<<"ADDITION:"<<r<<'.'<<p;
}
void main()
{
int a,b;
clrscr();
cout<<"Ruppes:";
cin>>a;
cout<<"Paisa :";
cin>>b;
currency ob1(a,b);
cout<<"Ruppes:";
cin>>a;
cout<<"Paisa :";
cin>>b;
currency ob2(a,b);
currency ob3(0,0);
ob3=ob1.add(ob2);
ob3.disp();
getch();
}
Comments
Post a Comment