Access Millions of academic & study documents

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

Content type
User Generated
Showing Page:
1/10
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

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/10
++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

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/10

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 10 pages?
Access Now
Unformatted Attachment Preview
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 whic ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Similar Documents