Question

A complex number is a number in the form of a + bi, where a and...

A complex number is a number in the form of a + bi, where a and b are real numbers and i is the square root of negative 1.

Design and create a class called Complex for representing complex numbers. This class should have two attributes, a and b, which represent the parts of the complex number. This class should overload the +,-,*,/,++ and -- operators (both prefix and suffix) to perform basic complex number calculations according to the following formulas:

a + bi + c + di = (a+c) + (b+d)i

a + bi - (c + di) = (a-c) + (b - d)i

(a + bi)*(c + di) = (ac - bd) + (bc + ad)i

(a + bi)/(c + di) = (ac + bd)/(c^2 + d^2) + (bc - ad)i/(c^2 + d^2)

For example, 5 + 3i + 6 + 2i = 11 + 5i

(5+3i)*(6+2i) = (5*6 - 3*2) + (3*6 + 5*2)i = 24 + 28i

++ and -- should simply add or subtract one to the real part (a)

Provide three constructors Complex (a,b), Complex (a) and Complex().

Complex() gives a number with a and b = 0, Complex(a) gives a number with a set but b=0, and Complex(a,b) sets both values. Your class should also have getRealPart() and getImaginaryPart() methods for returning the value of a and b respectively, as well as a method that returns the string representation of the number (to be used for displaying purposes later).

For the main program that will use the Complex class, prompt the user for how many complex numbers they wish to use. Then create an array of Complex numbers and prompt the user for values a and b for the entire array.

Now display the entire array and ask the user which number they would like to work with. Once the user has selected a number, ask the user if they would like to do a unary or binary operation. If they answer unary, prompt for ++prefix, postfix++, --prefix, postfix-- and then what number to store the result in. Then perform that operation. If they say they want to perform a binary operation, prompt for an operation (+,-,*,/) and then the second operand. Lastly, ask them in which number they wish to store the result. Perform the calculation and put the result where they told you to put it. In your code, use overloaded operators to do the work. This means you should implement overloaded operators of +,-,*,/,++,--(pre and post) and =(assignment).

If users have the following list of numbers

1) 5 + 3i

2) 2 - 4i

3) 3 + 5i

4) quit

and they select 1, then prompt them for

1) unary

2) binary

if they select 2, then ask user what type of operation

1) +

2) –

3) *

4) /

if they enter +, then redisplay the numbers and prompt them for the second operand

1) 5 + 3i

2) 2 - 4i

3) 3 + 5i

4) quit

If they enter 2, then ask them for where to store the result. Suppose they enter 3 for the result. Then you want to do number 1 + number 2 and store the result in element 3.

Example: (5+3i) + (2 - 4i) and store the result in number 3

program should continue with this in a menu until the user selects quit.

The program should deal with the divide by zero error by throwing an exception in the divide overload, catching it in the main body and outputting an appropriate error message, after which you can let the program terminate. Meaning, use a try/catch block to throw an error and end the program for divison by 0.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
A complex number is a number in the form of a + bi, where a and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • JAVA PROGRAMMING A complex number is a number in the form a + bi, where a...

    JAVA PROGRAMMING A complex number is a number in the form a + bi, where a and b are real numbers and i is V-1. The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas: a + bi + c + di = (a + c) + (b + di a + bi - (c +...

  • A complex number is a number of the form a + bi, where a and b...

    A complex number is a number of the form a + bi, where a and b are real numbers √ and i is −1. The numbers a and b are known as the real and the imaginary parts, respectively, of the complex number. The operations addition, subtraction, multiplication, and division for complex num- bers are defined as follows: (a+bi)+(c+di) = (a+c)+(b+d)i (a+bi)−(c+di) = (a−c)+(b−d)i (a + bi) ∗ (c + di) = (ac − bd) + (bc + ad)i (a...

  • Perform the indicated operation and write the answer in the form a +bi, where a and...

    Perform the indicated operation and write the answer in the form a +bi, where a and b are real numbers. 28) (6-5i)(7 +3i) A) -15;2 - 171 +42 B) 57 - 171 C) 27 - 531 D) 57 +171 Write the quotient in the form a +bi. 9 +41 29) 2-4i B) -1.4, C) -1 5 Use De Moivre's theorem to simplify the expression. Write the answer in a +bi form. 30) (3 (cos 120° + i sin 120°))4 A)...

  • A complex number is a number in the form a + bi, where a and b...

    A complex number is a number in the form a + bi, where a and b are real numbers and i is sqrt( -1). The numbers a and b are known as the real part and imaginary part of the complex number, respectively. You can perform addition, subtraction, multiplication, and division for complex numbers using the following formulas: a + bi + c + di = (a + c) + (b + d)i a + bi - (c + di)...

  • 2. A complex number can be expressed as a + bi where a and b are...

    2. A complex number can be expressed as a + bi where a and b are real numbers and i is the imaginary unit. The multiplication of two complex numbers is defined as follows: (a+bi)(c+di) = (ac-bd) + (bc+ad)i Define a class which represents a complex number. The only member functions you have to define and implement are those which overload the * and *= symbols.

  • c++ 2) Complex Class A complex number is of the form a+ bi where a and...

    c++ 2) Complex Class A complex number is of the form a+ bi where a and b are real numbers and i 21. For example, 2.4+ 5.2i and 5.73 - 6.9i are complex numbers. Here, a is called the real part of the complex number and bi the imaginary part. In this part you will create a class named Complex to represent complex numbers. (Some languages, including C++, have a complex number library; in this problem, however, you write the...

  • Create a class for working with complex numbers. Only 2 private float members are needed, the...

    Create a class for working with complex numbers. Only 2 private float members are needed, the real part of the complex number and the imaginary part of the complex number. The following methods should be in your class: a. A default constructor that uses default arguments in case no initializers are included in the main. b. Add two complex numbers and store the sum. c. Subtract two complex numbers and store the difference. d. Multiply two complex numbers and store...

  • #1,5,9 and #13,17,21,25 please. In Exercises 1-12, graph each complex number in the complex plane 3. -2 4i 2 2. 3 5i 7.-3i 8.-5i 6. 7 47 19 7 15 2 11 2 12. 10 10 each complex number in polar form...

    #1,5,9 and #13,17,21,25 please. In Exercises 1-12, graph each complex number in the complex plane 3. -2 4i 2 2. 3 5i 7.-3i 8.-5i 6. 7 47 19 7 15 2 11 2 12. 10 10 each complex number in polar form 15. 1 V3i 14. 2 + 2i 16. -3- V3i 3. 1-i 20. -V3+i 18. V5_V5İ 19. V3-3i 17-44i 24. -8-8V3i 22. 2 + Oi 2 23, 2v3-2i 21. 3 +0i V3 1 1 V3 28·16+161 26, 1...

  • Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form:...

    Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form: realPart + imaginaryPart * i where i is √-1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should contain default values of (1,1) i.e. 1 for the real part and 1 for the imaginary part. Provide public member functions that perform the following...

  • Do the indicated operation and write the answer in the complex form a + bi. a)...

    Do the indicated operation and write the answer in the complex form a + bi. a) (-5 + 7i)-(-2+ 3i) b) (6 + 7i)2 -3-2i c) 5+2 i

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT