/* write a c++ program using class to overload the operator unary
increment ++ for an integer number*/
#include<conio.h>
#include<iostream.h>
class increment
{
public:int no;
public:void getdata()
{
cout<<"\nenter the number:-";
cin>>no;
}
void operator ++()
{
no=no+1;
}
void display()
{
cout<<"\nthe number after increment is:-"<<no;
}
};
int main()
{
increment i;
clrscr();
i.getdata();
++i;
i.display();
getch();
return 0;
}
/*
enter the number:-2
the number after increment is:-3
*/
increment ++ for an integer number*/
#include<conio.h>
#include<iostream.h>
class increment
{
public:int no;
public:void getdata()
{
cout<<"\nenter the number:-";
cin>>no;
}
void operator ++()
{
no=no+1;
}
void display()
{
cout<<"\nthe number after increment is:-"<<no;
}
};
int main()
{
increment i;
clrscr();
i.getdata();
++i;
i.display();
getch();
return 0;
}
/*
enter the number:-2
the number after increment is:-3
*/
No comments:
Post a Comment