C++ program for overloading the unary operator ++.

ALGORITHAM:
• Start the process
• Invoke the class counter
• Crate two objects c1 and c2
• Assign values to c1 an c2
o Call c1.get_count()
o Call c2.get_count()
• Increment the values
o C1++
o C2++
o ++c2
• Print c1 and c2
• Stop the process

PROGRAM

#include<iostream.h>
#include<conio.h>
class counter
{
int count;
public:
counter()
{
	count=0;
}
int get_count()
{
return count;
}
void operator++()
{
count++;
}
};
 
void main()
{
counter c1,c2;
cout<<"\nC1 ="<<c1.get_count();
cout<<"\nC2 ="<<c2.get_count();
 
c1++; 		//Using overloaded ++ operator.
c2++;
++c2;
cout<<"\nC1 ="<<c1.get_count();
cout<<"\nC2 ="<<c2.get_count();
getch();
}

OUT PUT:
C1=0 C2=O
C1=1 C2=2

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

One thought on “C++ program for overloading the unary operator ++.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in