Question: #include int main() { const Complex a(1.2, 2.0); // create a complex number with real=1.2 imag=2.0 const Complex b(0.5, 0.0); // real = 0.5, imag
| #include | |
| int main() { | |
| const Complex a(1.2, 2.0); // create a complex number with real=1.2 imag=2.0 | |
| const Complex b(0.5, 0.0); // real = 0.5, imag = 0.0 | |
| const Complex c = a + b; // overload operator + using a friend function | |
| c.print(); // should print the following to cout: (1.5,2.0) | |
| // (member syntax). Should look the same as method add where the name add | |
| // is replaced by operator + | |
| const Complex d = a.add(b); // this should be the same as the above except the name | |
| d.print(); | |
| Complex e = -d; // implement unary - using a member operator. Since it has one parameter which is this should have ZERO PARAMETERS!!! | |
| cout << e << ' '; | |
| } |
1. Do not edit the main() function in any way.
2. Create a complex class in the same .cc file as main() that allows the program to compile and function properly. Pay special attention to the included comments in main() that
explain how to implement the complex class.
3. + member
- friend
* friend
<< friend
Example output
(1.5,2.0)
(1.5,2.0)
(-1.5,-2.0)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
