C++ program : To show Increament and Decreament operator overloading




#include<iostream.h>
#include<conio.h>
class op
{
   int no1;
   float no2;
   public:
   op(int a,float b)
   {
      no1=a;
      no2=b;
   }
   void operator++()
   {
      cout<<"\nOperator increamenting";
      no1++;
      no2++;
   }
   void operator--()
   {
      cout<<"\nOperator Decreamenting";
      no1--;
      no2--;
   }
   void show()
   {
      cout<<"\n no1 : "<<no1<<"\n no2 : "<<no2;
   }
};

int main()
{
   clrscr();
   int a;
   float b;
   cout<<"Enter two Number";
   cin>>a>>b;
   op ob(a,b);
   ob.show();
   ++ob;
   ob.show();
   --ob;
   ob.show();
   getch();
   return 0;
}



// Special Thanks to Gostkiller ( Midhul )...

Class diagram 

(click image to view large)

 

 



Related Posts:

0 comments:

Post a Comment