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

Important: For this code, it should be three parts: heater file, a c++ file, and

ID: 3631937 • Letter: I

Question

Important:
For this code, it should be three parts: heater file, a c++ file, and a test c++ file:
Complex Class: Create a class called Complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form

realPart + imaginaryPart * i
where i is sq root -1

Use double variables to represent the private data of the class. Proved a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks:

a) Adding two Complex numbers: The real parts are added together and the imaginary parts are added together.
b) Subtracting two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand, and the imaginary part of the right operand is subtracted from the imaginary part of the left operand.
c) Printing Complex numbers in the form (a,b) were a is the real part and b is the imaginary part.

Thanks a lot. I kind of know how to do C but im still new and a friend of mine told me to do C++ and presented me this problem but I have no idea how to do it.

Explanation / Answer

please rate - thanks

I added an example of how you could input the values of the parameters-hilighted in red

if there is a problem please message me before rating

the other answer should be at least helpful

#include <iostream>
#include <iomanip>
using namespace std;
class Complex
{public:
void displayComplex();
Complex(double,double);
Complex add(Complex x);
Complex subtract(Complex x);
private:
double real,imag;
};
Complex::Complex(double r=0,double i=0)
{real=r;
imag=i;
}
Complex Complex::add(Complex x)
{Complex temp;
temp.real=real+x.real;
temp.imag=imag+x.imag;
return(temp);}
Complex Complex::subtract(Complex x)
{Complex temp;
temp.real=real-x.real;
temp.imag=imag-x.imag;
return(temp);}
void Complex::displayComplex(void)
{cout<<fixed<<setprecision(2)<<"("<<real<<","<<imag<<")";
}
int main()
{double r,i;
cout<<"Enter real part: ";
cin>>r;
cout<<"enter imaginary part: ";
cin>>i;
Complex a(r,i),b(9,2),c;
Complex d(10,1),e(11,5);
c=a.add(b);
a.displayComplex();
cout<<" + ";
b.displayComplex();
cout<<" = ";
c.displayComplex();
cout<<endl;
c=d.subtract(e);
d.displayComplex();
cout<<" - ";
e.displayComplex();
cout<<" = ";
c.displayComplex();
cout<<endl;
system("pause");
return 0;
}