TRICTLY USE TEMPLATE PROVIDED AT END OF QUESTION. FOLLOW WHAT IS GIVEN IN QUESTION ------------------------------------------------------ Develop a program to overload binary operators. The class Complex has the following public attributes
STRICTLY USE TEMPLATE PROVIDED AT END OF QUESTION. FOLLOW WHAT IS GIVEN IN QUESTION
------------------------------------------------------
Develop a program to overload binary operators.
The class Complex has the following public attributes
Data type | Variable name |
int | real |
int | imaginary |
Note:- 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
-------------END OF QUESTION--------------
COMPLEX.CPP
#include<cstring> class Complex
|
MAIN.CPP
#include<cstring> #include<iostream> #include<string> #include "Complex.cpp" using namespace std; int main() { //fill your code here } |
Step by step
Solved in 2 steps with 2 images