Question: Design a class Complex having a real part (x) and an imaginary part (y) as data members. Add basic member functions to this class and

Design a class Complex having a real part (x) and an imaginary part (y) as data members.

Add basic member functions to this class and also methods to

1. add two complex numbers.

2. multiply two complex numbers

Test the above class with the following code in main() method.

Complex c1 = new Complex(2,3); //2+3i

Complex c2= new Complex(8,5); //8+5i

Complex c3 = new Complex();

Complex c4 = new Complex();

c3= c1.add(c2);

System.out.println(c3); //should print 10+8i

c4=c1.multiply(c2); should print 1+34i

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!