Tuesday, 20 March 2018

Overloading of Unary Operator

//Overloading of Unary Operator
#include<iostream.h>
#include<conio.h>
class complex
{
int a,b,c;
public:
 complex(){}
 void getvalue()
 {
  cout<<"\n\nEnter the Two Numbers:";
  cin>>a>>b;
 }
 void operator++()
 {
  a=++a;b=++b;
 }
 void operator--()
 {
  a=--a;b=--b;
 }
 void display()
 {
  cout<<a<<"+"<<b<<"i"<<endl;
 }
};
void main()
{
 clrscr();
 complex obj;
 obj.getvalue();
 obj++;
 cout<<"\nIncrement Complex Number\n";
 obj.display();
 obj--;
 cout<<"\n\nDecrement Complex Number\n";
 obj.display();
 getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.