Write a C++ program to create a class Integer. Write necessary member functions to overload the operator unary pre and post decrement ‘--’ for an integer number.
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<iostream.h>
#include<conio.h>
class integer
{
int a,b;
public:
void acc(int x,int y)
{
a=x;
b=y;
}
void operator -() //function overloading
{
a--;
--b;
}
void dis()
{
cout<<"\n a\t: "<<a;
cout<<"\n b\t: "<<b<<"\n";
}
};
void main()
{
int a,b;
integer i; //object created
cout<<"\nEnter Value of a:- ";
cin>>a;
cout<<"\nEnter Value of b:- ";
cin>>b;
i.acc(20,10);
cout<<"\n=======before========= "<<endl;
i.dis();
- i;
cout<<"\n=======after========== "<<endl;
i.dis();
getch();
}
0 Comments