Increment Program Using OOP C++
Increment Program Using OOP C++
Just open your c++ compiler Paste this code.
#include <iostream>
using namespace std;
class Counter
{
private:
unsigned int count;
public:
Counter() : count(0)
{ }
unsigned int get_count()
{ return count; }
void operator ++ ()
{ ++count; }
};
int main()
{
Counter c1, c2;
cout << "\nc1=" << c1.get_count();
cout << "\nc2=" << c2.get_count();
++c1;
++c2;
++c2;
cout << "\nc1=" << c1.get_count();
cout << "\nc2=" << c2.get_count() << endl;
return 0;
}
Just open your c++ compiler Paste this code.
#include <iostream>
using namespace std;
class Counter
{
private:
unsigned int count;
public:
Counter() : count(0)
{ }
unsigned int get_count()
{ return count; }
void operator ++ ()
{ ++count; }
};
int main()
{
Counter c1, c2;
cout << "\nc1=" << c1.get_count();
cout << "\nc2=" << c2.get_count();
++c1;
++c2;
++c2;
cout << "\nc1=" << c1.get_count();
cout << "\nc2=" << c2.get_count() << endl;
return 0;
}








0 comments: