OOPS-Passing objects by functions

 #include <iostream>

using namespace std;

class Complex

{

    private:

    int a,b;

    public:

    void add(int a1, int b1)

    {

        a=a1;

        b=b1;

    }

    

    void complexadd(Complex o1, Complex o2)

    {

        a=o1.a+o2.a;

        b=o1.b+o2.b;

    }

    

    void display()

    {

        cout<<"The number is"<<a<<"+i"<<b<<endl;

    }

    

    

};

int main() {

Complex o1;

o1.add(3,4);

o1.display();

Complex o2;

o2.add(5,6);

o2.display();

Complex o3;

o3.complexadd(o1,o2);

o3.display();

return 0;

}


Comments

Popular posts from this blog

Hackerrank-Accessing Inherited Functions problem-Inheritance

Inheritance- Code with Harry-Lecture 41 solution (Multiple inheritance)