Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Four integers are read from input, where the first two integers are the real and imaginary parts of complexNumber 1 and the second two integers
Four integers are read from input, where the first two integers are the real and imaginary parts of complexNumber and the second two integers are the real and imaginary parts of complexNumber Define two functions to overload the operator. The first function overloads the operator to subtract a complex number and an integer representing the real part of the complex number. The second function overloads the operator to subtract two complex numbers.
Ex: If the input is then the output is:
ii
iii
Note:
A complex number consists of a real part and an imaginary part. Ex: i where is the real part and is the imaginary part.
The difference of a complex number and an integer representing the real part of the complex number, i is:
the difference of the real part of the complex number and the integer,
the imaginary part is unchanged
Thus, the difference is i
The difference of two complex numbers, i and i is the difference of their real parts and the difference of their imaginary parts i i Thus, the difference is i CODE: #include
using namespace std;
class ComplexNumber
public:
ComplexNumberint realPart int imaginaryPart ;
void Print const;
ComplexNumber operatorint rhs;
ComplexNumber operatorComplexNumber rhs;
private:
int real;
int imaginary;
;
ComplexNumber::ComplexNumberint realPart, int imaginaryPart
real realPart;
imaginary imaginaryPart;
No need to accommodate for overflow or negative values
Your code goes here
void ComplexNumber::Print const
cout real imaginary i;
int main
int realPart;
int imaginaryPart;
int realPart;
int imaginaryPart;
cin realPart;
cin imaginaryPart;
cin realPart;
cin imaginaryPart;
ComplexNumber complexNumberrealPart imaginaryPart;
ComplexNumber complexNumberrealPart imaginaryPart;
ComplexNumber difference complexNumber realPart;
ComplexNumber difference complexNumber complexNumber;
cout ;
complexNumberPrint;
cout realPart;
differencePrint;
cout endl;
cout endl;
cout ;
complexNumberPrint;
cout ;
complexNumberPrint;
cout ;
differencePrint;
cout endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started