Write a C++ program to count the number of persons inside a bank, by increasing count whenever a person enters a bank, using an increment(++) operator overloading function, and decrease the count whenever a person leaves the bank using a decrement(--) operator overloading function inside a class.


Implementation of the above problem:
#include<iostream.h>
#include<conio.h>
class counter
{
int count;
public:
counter()
{
count=0;
}
counter operator++(int)
{
count++;
}
int get_count()
{
return count;
}

counter operator--(int)
{
count--;
}
};
void main()
{
clrscr();
counter c1;
cout<<"Initial No Of People "<<c1.get_count()<<endl;
c1++;
c1++;
c1++;
cout<<"Present No Of People "<<c1.get_count()<<endl;
c1--;
c1--;
cout<<"Present No Of People "<<c1.get_count()<<endl;
getch();

}


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: