Friday, 22 June 2012

write a c++ program using class to overload the operator unary decrement ++ for an integer number

/* write a c++ program using class to overload the operator unary
decrement ++ for an integer number*/
#include<conio.h>
#include<iostream.h>
class decrement
{
public:int no;
public:void getdata()
       {
       cout<<"\nenter the number:-";
       cin>>no;
       }
       void operator --()
       {
       no=no-1;
       }
       void display()
       {
       cout<<"\nthe number after decrement is:-"<<no;
       }
};
int main()
{
decrement i;
clrscr();
i.getdata();
--i;
i.display();
getch();
return 0;
}
/*

enter the number:-6

the number after decrement is:-5
*/

No comments: