Question: C++ Define a class for complex numbers. A complex number is a number with two components, namely, the real part and the imaginary part. For

C++

Define a class for complex numbers. A complex number is a number with two components, namely, the real part and the imaginary part. For example the complex number (x, y).

x and y are numbers of type double, where x represent the part real and y represents the part imaginary. (e.g. when we have a complex number a (1,-5), the real = 1 and the imaginary =-5)

You need to:

Define the class Complex. Include a constructor with two parameters of type double which will be used to set the double variables real and imaginary to 0.

Write operator overloading for the following operators , so they correctly apply to the object Complex: +, -, *, /, ++, --,==, !=, and <<

Write friend functions for norm as follow:

double (norm (const complex& x){

return real * real + imag*imag;

}

The class details and operations should be in a header file.

Use the following main function to test your program:

int main(){

complex x, y(5), z(-1.5, 2.5);

cout <<"x= "<< x<<"y = "<< y<< "z= " <

x = complex (1, -2);

cout<< "test output operator: "<<"complex number x = "<< x <

cout<<"test complex arithmetic and output routines: ";

y = complex (2,-2);

cout<<"x = "<

z= x+y;

cout<<" z = x +y = "<

z=x*/ y;

cout<<"z = x*y = "<

z= x-y;

cout<<" z = x -y = "<

z=x / y;

cout<<"z = x/y = "<

cout<<"x is "<

cout<<"y is "<

x=y;

if (x==y)

cout<

if (x!=z)

cout<

return 0;

}

You need to send the following: the .cpp file and .h file

(Write the appropriate comments, define class, define function)

Show the output :

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!