Write a C program that displays characteristics of a number
Write a C++ program that displays characteristics of a number depending on whether it is a real
or a complex number.
1.The user is asked if he wants the characteristics of a real number (choice 1) or a complex
number (choice 2).
2. The following applies to CHOICE 1:
a. Obtain a real number (whole number) from the user.
b. Display the following characteristics:
i. Integer Part
ii. Fractional Part
iii. Round: Rounding value to the next integer if the fractional part is > 0.5 else it
is approximated to the integer part of the number.
iv. Floor
v. Ceil
2. The following applies to CHOICE 2:
a. Obtain the real part of the complex number and the imaginary part of the complex
number from the user. (Ex: X + Yj => X is the real part and Y is the complex part)
b. Display the following characteristics:
i. Real Part
ii. Imaginary Part
iii. Complex conjugate: Complex conjugate is obtained by reversing the sign of
the complex part entered by the user. For ex: If X + Yj is the complex conjugate of X – Yj)
iv. Magnitude of the complex number: Formula: sqrt (X2 + Y2 )
v. Phase of the complex number, in degrees: Formula = atan (Y/X) * (180/PI)
Note: atan is a pre-defined function in cmath and PI is a const defined in cmath
Requirements:
1. You are not required to check for wrong inputs from the user. Assume right values for
Choices 1 and 2.
2. You are required to use functions (user-defined functions) for the following operations:
a. Round for choice 1
b. Magnitude for choice 2
c. Phase for choice 2
3. You are required to use pre-defined (library) functions for the following operations:
a. Floor for Choice 1
b. Ceil for Choice 1
4. For the remaining characteristics, using functions is optional.
5. Be careful about dividing by zero for a pure-complex number (X=0) while computing the
phase of the complex number. In this case, you can set the Phase of the complex number
(in degrees) to 90.
Solution
# include
