Develop a C++ program to increment the complex number by overloading ++ operator.
#include <iostream>
using namespace std;
class Complex{
float a, b;
public:
Complex(): a(0), b(0) {}
Complex(float x, float y): a(x), b(y){}
void display(){
cout<<this->a<<" + "<<this->b<<"i"<<endl;
}
Complex operator++(){
this->a++;
this->b++;
return *this;
}
Complex operator++(int){
this->a++;
this->b++;
return *this;
}
};
int main(){
Complex complex(1, 1);
complex.display();
complex++;
complex.display();
++complex;
complex.display();
return 0;
}
Comments
Leave a comment