C++ Calculator for complex numbers - follow-up After following the suggestions from the first question on that topic (link), I'd like to show you the result now:

#include &lt;iostream&gt;

class ComplexNumber {

    private:
        double real;
        double imaginary;

    public:
        ComplexNumber operator+(ComplexNumber b) {

            //Just add real- and imaginary-parts
            double real = this-&gt;real + b.real;
            double imaginary = this-&gt;imaginary + b.imaginary;
            ComplexNumber c = ComplexNumber(real, imaginary);
            return c;
        }

        ComplexNumber operator-(ComplexNumber b) {

            //Just subtract real- and imaginary-parts
            double real = this-&gt;real - b.real;
            double imaginary = this-&gt;imaginary - b.imaginary;
            ComplexNumber c = ComplexNumber(real, imaginary);
            return c;
        }

        ComplexNumber operator*(ComplexNumber b) {

            //Use binomial theorem to find formula to multiply complex numbers
            double real = this-&gt;real * b.real - this-&gt;imaginary * b.imaginary;
            double imaginary = this-&gt;imaginary * b.real + this-&gt;real * b.imaginary;
            ComplexNumber c = ComplexNumber(real, imaginary);
            return c;
        }


        ComplexNumber operator/(ComplexNumber b) {

            //Again binomial theorem
            double real = (this-&gt;real * b.real + this-&gt;imaginary * b.imaginary) / (b.real * b.real + b.imaginary * b.imaginary);
            double imaginary = (this-&gt;imaginary * b.real - this-&gt;real * b.imaginary) / (b.real * b.real + b.imaginary * b.imaginary);
            ComplexNumber c = ComplexNumber(real, imaginary);
            return c;
        }

        void printNumber(char mathOperator) {
            std::cout &lt;&lt; "a " &lt;&lt; mathOperator &lt;&lt; " b = " &lt;&lt; this-&gt;real &lt;&lt; " + (" &lt;&lt; this-&gt;imaginary &lt;&lt; ") * i" &lt;&lt; std::endl; 
        }

    /*
     * Constructor to create complex numbers
     */
    ComplexNumber(double real = 0.0, double imaginary = 0.0) {
        this-&gt;real = real;
        this-&gt;imaginary = imaginary;
    }
};

int main() {

    /*
     * Variables for the real- and imaginary-parts of
     * two complex numbers
     */
    double realA;
    double imaginaryA;
    double realB;
    double imaginaryB;

    /*
     * User input
     */
    std::cout &lt;&lt; "enter real(A), imag(A), real(B) and imag(B) &gt;&gt; ";
    std::cin &gt;&gt; realA &gt;&gt; imaginaryA &gt;&gt; realB &gt;&gt; imaginaryB;
    std::cout &lt;&lt; std::endl;

    /*
     * Creation of two objects of the type "ComplexNumber"
     */
    ComplexNumber a(realA, imaginaryA);
    ComplexNumber b(realB, imaginaryB);

    /*
     * Calling the functions to add, subtract, multiply and 
     * divide the two complex numbers.
     */
    ComplexNumber c = a + b;
    c.printNumber('+');

    c = a - b;
    c.printNumber('-');

    c = a * b;
    c.printNumber('*');

    c = a / b;
    c.printNumber('/');

    return 0;
}


If you have any suggestions on further improving the code, I would really appreciate it if you share them with me.
Use field initialization lists:

So your constructor

ComplexNumber(double real = 0.0, double imaginary = 0.0) {
    this-&gt;real = real;
    this-&gt;imaginary = imaginary;
}


Can become:

ComplexNumber(double real = 0.0, double imaginary = 0.0)
    : real(real), imaginary(imaginary) { }


Simplify your returns

I could see an argument for making an extra ComplexNumber to hold your return value if you need to further modify it or if the name of that variable is explanatory in showing what the return means, but as it stands, your c is neither of those.

Simplify

ComplexNumber c = ComplexNumber(real, imaginary);
return c;


To just

return ComplexNumber(real, imaginary);


Make your operator functions const

Since you (correctly) don't modify a when you do a + b, the operator function can (and should) be declared const. That way, even if you have a const object, you'll still be able to call it (and if you accidentally try to modify the member variable, you'll know immediately in the form of a compilation error).

That'd look like:

ComplexNumber operator+(const ComplexNumber &amp;b) const {


Notice I've also declared b as const here since you shouldn't be modifying it either. I've also passed it by reference to save you some overhead.

Make your class printable with std::cout

Your printNumber is very specific. In fact, if you ever want to use this class for anything other than simply showing arithmetic results, that print may not be what you want. Instead, I'd make a generic str() that just returns a string version of the complex number. Something like:

std::string str() {
    std::ostringstream oss;
    oss &lt;&lt; this-&gt;real &lt;&lt; " + (" &lt;&lt; this-&gt;imaginary &lt;&lt; ") * i";
    return oss.str(); 
}


And then in the global scope, you can overload the &lt;&lt; operator for std::cout:

std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, const ComplexNumber &amp;cn) {
    return os &lt;&lt; cn.str();
}


And now when you want to print it in main(), you can say:

std::cout &lt;&lt; "a + b = " &lt;&lt; a + b &lt;&lt; std::endl;
std::cout &lt;&lt; "a - b = " &lt;&lt; a - b &lt;&lt; std::endl;
std::cout &lt;&lt; "a * b = " &lt;&lt; a * b &lt;&lt; std::endl;
std::cout &lt;&lt; "a / b = " &lt;&lt; a / b &lt;&lt; std::endl;


Look at how easy that becomes to read and understand!