Answer to Question #184180 in C++ for lohith

Question #184180

Create a class Complex to represent complex number. Using this pointer perform addition of two complex numbers. 


Member function for adding A=A+B 


Complex Add(Complex B) 



   //use this for accessing Object A of Complex class 


}


1
Expert's answer
2021-04-22T05:44:11-0400
#include<iostream>
using namespace std;
class Complex{
public:
    int real;
    int imag;
     /* Function to set the values of
      * real and imaginary part of each complex number
      */
     void setvalue()
    {
        cin>>real;
        cin>>imag;
    }
	/* Function to display the sum of two complex numbers */
    void display()
    {
        cout<<real<<"+"<<imag<<"i"<<endl;
    }
	/* Function to add two complex numbers */
 
    void sum(Complex A, Complex B)
    {
        real=A.real+B.real;
        imag=A.imag+B.imag;
    }
    };
int main()
    {
        Complex A,B,c3;
        cout<<"Enter real and imaginary part of first complex number"<<endl;
        A.setvalue();
        cout<<"Enter real and imaginary part of second complex number"<<endl;
        B.setvalue();
        cout<<"Sum of two complex numbers is"<<endl;
        c3.sum(c1,c2);
        c3.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