Question
This
assignment will test your programming skills in C++ as well as your
understanding about operator overloading and friend functions. Here, you will
be required to develop a simple mathematical application which will be able to
perform the normal mathematical operations ( i.e. add, subtract, multiply and
divide ) on complex numbers.
For those who
are unfamiliar with complex numbers, kindly refer to the article provided by
the link below which gives a very clear explanation on this topic.
https://www.mathsisfun.com/numbers/complex-numbers.html
Briefly, a complex number is a
number which contains a real and imaginary part and is written in the form a +
bi where a is the real part of the complex number and bi
the imaginary part. An example of an
imaginary number is 2 + 3i. i has the special characteristic
that i2
= -1.
Thus, if num1 and num2 are both
complex numbers and num1 = 3 + 4i and num2 = 3 –
4i, then the following should be observed and produced by your program:
(a) num1
+ num2 = 6
(b) num1
– num2 = 8i
(c) num1
* num2 = 25
(d) num1
/ num2 = 0.04(-7+24i)
Note: When an
operation acts on two complex numbers, it is possible that the results can be
either a number consisting only of a real part, an imaginary part or both )
In this assignment, you will be
specifically required to ensure that the following are included in your program
:
(a)
You need to create the appropriate
class to represent complex numbers. The complex numbers should consist of a
real and imaginary part and both the real and imaginary parts of the number
should be declared as floating point numbers.
(b)
You need to overload the four common
mathematical operators which act on complex numbers i.e. the multiplication,
division, addition and subtraction operators. The operators should act on the
complex numbers as explained above.
(c)
You need to write an appropriate function to
print out the results of the operations performed and the results should be
printed either in the form a + bi or a + ib.
(d)
You need to write a main program using suitable
test complex numbers to confirm that your program works correctly.
(e)
Ensure that proper and adequate comments is
provided in your program to explain how your program works. Make sure that you
indent your programs appropriately and use meaningful names for attributes and
methods.
It is
anticipated that your program should only be between 100 to 150 lines ( without
comments ) if you plan correctly. You will be required to submit the completed
program with the output using test results to the exam department before 5.00pm
on Wednesday 12th February 2020. You will also be required to mail
to me a copy of your source code to enable me to perform further checking.
Get Free Quote!
284 Experts Online