BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Object Oriented Programming (http://bzupages.com/35-object-oriented-programming/)
-   -   How to use Uniry Operator on class objects using C++ (http://bzupages.com/f35/how-use-uniry-operator-class-objects-using-c-1057/)

shmsa 24-10-2008 03:59 PM

How to use Uniry Operator on class objects using C++
 
Code:

#include
using namespace std;
class product
{
private:
 int count;
 
public:
 void getcount()
 {
  cout<<"Plz enter the value of count = ";
  cin>>count;
 }
 product (): count(6)
 { }

 
 void operator ++()
 {
  ++count;
  cout<<"it is pre increment"<  }
 void operator ++(int)
 {
  count++;
  cout<<"it is post increment"<  }

 void show()
 {
  cout<<"the value of count  after increment is = "<  }
};
 
class product1
{
private:
 int count;
 
public:
 void getcount()
 {
  cout<<"Plz enter the value of count = ";
  cin>>count;
 }
 product ()
 {count=6;}
 void operator --()
 {
  --count;
  cout<<"it is pre decrement"<  }
 void operator --(int)
 {
  count--;
  cout<<"it is post decrement"<  }

 void show()
 {
  cout<<"the value of count after decrement is = "<  }
};
void main()
{
 product p;
 p.getcount();
 ++p;
 p.show();
 p.getcount();
 p++;
 p.show();

 product1 p1;

 p1.getcount();
 --p1;
 p1.show();
 p1.getcount();
 p1--;
 p1.show();
}

it is done in 2 classes it can also be done in 1 class:bigok:


All times are GMT +5. The time now is 08:39 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.