Answer to Question #186170 in C++ for Ajith

Question #186170

Develop a C++ program to increment the complex number by overloading ++ operator.


1
Expert's answer
2021-04-27T06:21:08-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS