QUESTION PROVIDED BELOWKINDLY SEE. PROVIDE OUTPUT AS IT IS SHOWN IN QUESTION. AND FOLLOW TEMPLATES PROVIDED AT END OF QUESTION CHECK THIS BEFORE MAKING SOLUTION ( main.cpp , COMPLEX.cpp ) ----------------- TEMPLATES BELOW FOR SOLUTION ----------------------- 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 ------------------------QUESTION ENDS--------------- --------------TEMPLATES BELOW--------------- main.cpp #include #include "Complex.cpp" using namespace std; int main() { //Fill your code here return 0; } complex.cpp #include using namespace std; class Complex { //Fill your code here public: Complex operator+(Complex a2){ //Fill your code here } Complex operator-(Complex a2){ //Fill your code here } Complex operator*(Complex a2){ //Fill your code here } Complex operator/(Complex a2){ //Fill your code here } void display() { //Fill your code here } };
QUESTION PROVIDED BELOWKINDLY SEE. PROVIDE OUTPUT AS IT IS SHOWN IN QUESTION.
AND FOLLOW TEMPLATES PROVIDED AT END OF QUESTION CHECK THIS BEFORE MAKING SOLUTION ( main.cpp , COMPLEX.cpp )
----------------- TEMPLATES BELOW FOR SOLUTION -----------------------
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
------------------------QUESTION ENDS---------------
--------------TEMPLATES BELOW---------------
main.cpp
#include<iostream> #include "Complex.cpp" using namespace std; int main() { //Fill your code here return 0; } |
complex.cpp
#include<iostream> class Complex public: Complex operator-(Complex a2){ Complex operator*(Complex a2){ Complex operator/(Complex a2){ |
Step by step
Solved in 3 steps with 1 images