program in c++ and must match output as it is . ------------------------------------ Develop a program to overload binary operators. The class Complex has the following public attributes Data type Variable name int real
------------------------------------
Develop a program to overload binary operators.
The class Complex has the following public attributes
Data type | Variable name |
int | real |
int | imaginary |
Include default constructor to initialize real and imaginary values to 0
Include the following functions in the Complex class and overload the binary operators
Member function | Function description |
void getvalue() | This function is used to read inputs |
Complex operator+(const Complex& obj) |
This function will add the real and imaginary parts |
Complex operator-(const Complex& obj) |
This function will subtract the real and imaginary parts |
void display() | This function will display the result value |
In main() function invoke the operator overloading by creating objects for the Complex class. Below statements should be printed in the main() function itself
- Enter the value of Complex Numbers a,b :
- Enter the value of Complex Numbers a,b :
- Input Values :
- Result :
Sample Input and Output :
[All texts in bold represents input and rest represents output statements]
Enter the value of Complex Numbers a,b :4 5
Enter the value of Complex Numbers a,b :7 8
Input Values :
Output Complex number : 4+5i
Output Complex number : 7+8i
Result :
Output Complex number : 11+13i
Output Complex number : -3-3i
Step by step
Solved in 2 steps with 2 images