Complex

 avatar
SAT
c_cpp
4 months ago
564 B
2
Indexable
#include <iostream>

using namespace std;

class Complex{
    private:
        int real, img;
    
    public:
    Complex(){

    }
    Complex(int real, int img){
        this->real = real;
        this->img = img;
    }
    void disp(){
        cout<<real<<" +i"<<img<<endl;
    }
    Complex operator +(Complex &C){
        Complex ans;
        ans.real = real + C.real;
        ans.img = img + C.img;
        return ans;
    }
};

int main(){
    Complex C1(2,3);
    Complex C2(4,5);
    Complex C3 = C1 + C2;
    C3.disp();
}
Editor is loading...
Leave a Comment