WAP TO OVERLOADING ARITHMETIC OPERATORS
#include<conio.h>
class arithmatic
{
float n;
public:
void get()
{
cout<<”\nEnter number: \n”;
cin>>n;
}
arithmatic operator+(arithmatic &a)
{
arithmatic t;
t.n=n+a.n;
return t;
}
arithmatic operator-(arithmatic &a)
{
arithmatic t;
t.n=n-a.n;
return t;
}
arithmatic operator*(arithmatic &a)
{
arithmatic t;
t.n=n*a.n;
return t;
}
arithmatic operator/(arithmatic &a)
{
arithmatic t;
t.n=n/a.n;
return t;
}
void display()
{
cout<<n;
}
};
void main()
{
arithmatic a1,a2,a3;
clrscr();
a1.get();
a2.get();
a3=a1+a2;
cout<<”\n\nAddition of two number: “;
a3.display();
a3=a1-a2;
cout<<”\n\nSubtraction of Two number: “;
a3.display();
a3=a1*a2;
cout<<”\n\nMultiplication of two number: “;
a3.display();
a3=a1/a2;
cout<<”\n\nDivision of two number: “;
a3.display();
getch();
}
No comments:
Post a Comment