Opeartor for complex Write a method to implement operator fo

Opeartor++ for complex

Write a method to implement operator++ for the Complex class. This method should result in the number having one added to the real component and return the new value of the number. This is the prefix version of the operator, so it would be used like this: Complex b = ++a; Write the code that would be in the cpp file. The header file contains: Complex &operator;++ ();//increments a Complex number by one FYI: The postfix version is similar, but uses a dummy ml parameter to distinguish itself from the prefix version. The postfix version also returns by value, instead of reference.

Solution

Hi Lets assume that \'real\' and \'imag\' are two fields of Complex class and there is parameterised constructor:

Complex(int r, int img)

Then implementation of ++ function:


Complex &operator++(){
   Complex inc(real+1, imag);
   return inc;
}

Opeartor++ for complex Write a method to implement operator++ for the Complex class. This method should result in the number having one added to the real compon

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site