Answer to Question #172748 in C++ for Panjumin

Question #172748

Create the class Complex that has floating point data members for storing real and imaginary parts and perform complex number addition. The class Complex has the following member functions: Complex() - Null constructor invokes when an object is created Complex(float, float) - Parameterized constructor to set the specified value of real and imaginary parts in object friend complex sum(complex, complex) - Friend function to perform complex number addition and return complex number display() - Function to display complex number object


1
Expert's answer
2021-03-20T23:11:06-0400
#include<iostream>

using namespace std;

class complex

{

int real,imag;

public:

void set()

{

cout<<"enter real and imag part";

cin>>real>>imag;

}

friend complex sum(complex,complex);

void display();

};

void complex::display()

{

cout<<"the sum of complex num is"<<real<<"+i"<<imag;

}

complex sum(complex a,complex b)

{

complex t;

t.real=a.real+b.real;

t.imag=a.imag+b.imag;

return t;

}

int main()

{

complex a,b,c;

a.set();

b.set();

c=sum(a,b);

c.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