Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Basic C++ please help thanks. Create a class called Complex for performing arith

ID: 3689565 • Letter: B

Question

Basic C++ please help thanks.

Create a class called Complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form real Part + imaginaryPart * i where i is squareroot 1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in ease no initializers are provided. Provide public member functions that perform the following tasks: Adding two Complex numbers: The real parts are added together and the imaginan,' parts are added together. Subtracting two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand, and the imaginan,' part of the right operand is subtracted from the imaginan,' pan of the left operand. Printing Complex numbers in the form (a, b), where a is the real part and b is the imaginary part.

Explanation / Answer

#include <iostream>
using namespace std;

class Complex
{
    private:
    double realPart,imagPart;
    public:
            Complex(Complex &c)
            {
                 this->realPart=c.realPart;
               this->imagPart=c.imagPart;
            }

    Complex(double r=0.0, double i=0.0)
    {
        realPart=r;
        imagPart=i;
    }
  
    void print()
    {
        cout<<"("<<realPart<<","<<imagPart<<")";
    }
    void add(Complex a)
    {
        Complex sum;
        sum.realPart=realPart+a.realPart;
        sum.imagPart=realPart+a.imagPart;
        cout<<" Sum: ";
        sum.print();
    }
    void sub(Complex a)
    {
        Complex diff;
        diff.realPart=realPart-a.realPart;
        diff.imagPart=realPart-a.imagPart;
        cout<<"Diff: ";
        diff.print();
    }
};

int main()
{
Complex a(12,12);
Complex b(4,5);
a.print();
a.add(b);
a.sub(b);
   return 0;
}