Unary operator condition increment or deferment in c + +
#include<iostream.h>
#include<conio.h>
class number
{
private:
int a,b;
public:
void input(int x,int y)
{
a=x;
b=y;
}
void display()
{
cout<<"\n a="<<a;
cout<<"\n b="<<b;
}
void operator++()
{
a=++a;
}
void operator--()
{
b=--b;
}
};
int main()
{
number n1;
clrscr();
int x,y;;
cout<<"\n enter thevalue of x:";
cin>>x;
cout<<"\n enter the value of y:";
cin>>y;
n1.input(x,y);
n1.display();
if(x>y)
{
++n1;
}
else
{
--n1;
}
n1.display();
getch();
return 0;
}
#include<conio.h>
class number
{
private:
int a,b;
public:
void input(int x,int y)
{
a=x;
b=y;
}
void display()
{
cout<<"\n a="<<a;
cout<<"\n b="<<b;
}
void operator++()
{
a=++a;
}
void operator--()
{
b=--b;
}
};
int main()
{
number n1;
clrscr();
int x,y;;
cout<<"\n enter thevalue of x:";
cin>>x;
cout<<"\n enter the value of y:";
cin>>y;
n1.input(x,y);
n1.display();
if(x>y)
{
++n1;
}
else
{
--n1;
}
n1.display();
getch();
return 0;
}
Comments
Post a Comment