class and objects program using unary operator

c++

Program:

Define – unary operator that inverts the value of object for counter class and should allow the statements like c1= – c1; or c2= – c1.

#include<iostream>

using namespace std;

class counter

{

int count;

public:

counter()

{

count=0;

}

 

int get_count()

{

return count;

}

counter operator ++()

{

counter temp;

temp.count=++count;

return temp;

}

 

counter operator – ()

{

counter temp;

temp.count=-count;

return temp;

}

};

 

int main()

{

counter c1,c2;

c2=++c1;

c2=++c1;

cout<<“\nc1 is:\n”<<c1.get_count()<<“\n\n”;

c1=-c1;

cout<<“\ninverse is:\n”<<c1.get_count()<<“\n\n”;

 

}

(isme overloading function k bagher b count ki value set kar skte hen)

Your comment are valueable