Write a C++ program using the operator overloading concept and display its results. Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement. Consider a class named Complex with the private member variables.
OUTPUT MUST MATCH AS IT IS
----------------------------------
Write a C++ program using the operator overloading concept and display its results.
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.
Consider a class named Complex with the private member variables.
Datatype | Variable |
int | real |
int | imaginary |
Include the private member variables and the constructor in the class Complex.
Define the following public methods in the class Complex.
Method Name | Description |
Complex operator+(Complex a2) | This function is used to perform the additional operation of the two complex numbers and returns the result. |
Complex operator-(Complex a2) | This function is used to perform the subtraction operation of the two complex numbers and returns the result. |
complex operator*(complex a2) | This function is used to perform the multiplication operation of the two complex numbers and returns the result. |
complex operator/(complex a2) | This function is used to perform the division operation of the two complex numbers and returns the result. |
void display() | This function is used to display the complex numbers |
In the main method get the inputs from the user and performs the operator overloading concept.
Input and Output Format :
Refer to sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.
Sample Input and Output 1 :
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Exit
Enter the choice :
Enter The First Complex Number:
Enter Real Part:
5
Enter Imaginary Part:
2
Complex number is = 5+2i
Enter The Second Complex Number:
Enter Real Part:
4
Enter Imaginary Part:
1
Complex number is = 4+1i
Addition of two Complex number is = 9+3i
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Exit
Enter the choice :
3
Enter The First Complex Number:
Enter Real Part:
4
Enter Imaginary Part:
3
Complex number is = 4+3i
Enter The Second Complex Number:
Enter Real Part:
5
Enter Imaginary Part:
2
Complex number is = 5+2i
Multiplication of two Complex number is = 14+23i
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Exit
Enter the choice :
5
Sample Input and Output 2 :
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Exit
Enter the choice :
2
Enter The First Complex Number:
Enter Real Part:
6
Enter Imaginary Part:
3
Complex number is = 6+3i
Enter The Second Complex Number:
Enter Real Part:
4
Enter Imaginary Part:
2
Complex number is = 4+2i
Subtraction of two Complex number is = 2+1i
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Exit
Enter the choice :
4
Enter The First Complex Number:
Enter Real Part:
6
Enter Imaginary Part:
3
Complex number is = 6+3i
Enter The Second Complex Number:
Enter Real Part:
4
Enter Imaginary Part:
1
Complex number is = 4+1i
Division of two Complex number is = 1+0i
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Exit
Enter the choice :
5
Step by step
Solved in 4 steps with 2 images