Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A partial implementation of a Complex number class is given below. A Complex object represents a complex number. Complex objects may be added or subtracted
A partial implementation of a Complex number class is given below. A Complex object represents a complex number. Complex objects may be added or subtracted using the overloaded operators + and -.
class Complex { private: double re; double im; public: Complex() : re(0), im(0) {}; Complex(double r, double i) : re(r), im(i) {}; Complex operator+(const Complex & c) { return Complex(re+c.re, im+c.im); } Complex operator-(const Complex & c) { return Complex(re-c.re, im-c.im); } };
Add the following features to the Complex class:
- An overloaded * operator that multiplies two complex numbers
- An overloaded / operator to divide two complex numbers
- An overloaded << operator that allows a Complex object to be passed to cout for printing
When the following test code is run from main()
Complex c1(1,-2); Complex c2(3,-4); Complex c3(-3,2); cout << (c1 + c2 - c2 - c1); cout << endl; cout << ((c1-c2)/c3 + c1*c3);
your code should produce a printout similar to this:
0 1.76923 + 8.15385j
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