Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement a class for arithmetic using imaginary numbers ( a + i b ) . The class has the following constructors and overloaded operators: *
Implement a class for arithmetic using imaginary numbers a i b The class has the following constructors and overloaded operators:
A constructor with no arguments sets the real and imaginary parts of the object to values
A constructor with two arguments a and b sets the real part to parameter a and the imaginary part to parameter b
Operator adds to imaginary numbers.
Operator subtracts two imaginary numbers.
Operator multiplies two imaginary numbers.
Operator displays an imaginary number.
Operator reads an imaginary number.
Operator assigns the rightside object to the left side object, eg a b
Operator returns true if two imaginary numbers are equal and falseotherwise
Operator returns true if two imaginary numbers are different and false otherwise.
The main program should demonstrate the use of all the above constructors and overloaded operators.
And fix the error of the code below.
#include
#include
#include
using namespace std;
class Imaginary
public:
Imaginary ;
Imaginary float a float b;
Imaginary& operatorImaginary &a;
operatorImaginary& v;
friend ostream& operatorostream& out, Imaginary& a;
private:
float real;
float imag;
;
Imaginary :: Imaginary
real ; imag ;
Imaginary :: Imaginary float a float b
real a; imag b;
Imaginary& Imaginary :: operatorImaginary& a
Imaginary v;
vreal real aimag;
vimag imag aimag;
return v;
Imaginary :: operatorImaginary& v
real vreal;
imag vimag;
ostream& operatorostream& out, Imaginary& a
out areal i aimag endl;
return out;
int main
class Imaginary in in in;
in in in;
cout in;
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