Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

9. Describe the characteristics of power.

Answered: 1 week ago