View Single Post
  #1  
Old 24-10-2008, 03:59 PM
shmsa's Avatar
shmsa shmsa is offline
Grown up punk

 
Join Date: Oct 2007
Location: Muslim Town Multan
Posts: 195
Contact Number: 0322-6196713
Program / Discipline: BSIT
Class Roll Number: 07-22
shmsa is a jewel in the roughshmsa is a jewel in the roughshmsa is a jewel in the roughshmsa is a jewel in the rough
Read How to use Uniry Operator on class objects using C++

Code:
#include <iostream>
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"<<endl;
 }
 void operator ++(int)
 {
  count++;
  cout<<"it is post increment"<<endl;
 }

 void show()
 {
  cout<<"the value of count  after increment is = "<<count<<endl;
 }
};
 
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"<<endl;
 }
 void operator --(int)
 {
  count--;
  cout<<"it is post decrement"<<endl;
 }

 void show()
 {
  cout<<"the value of count after decrement is = "<<count<<endl;
 }
};
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
Reply With Quote