I need to do a header ccomplex.h please help!!!!!! Define the class CComplex.cpp
ID: 3569336 • Letter: I
Question
I need to do a header ccomplex.h please help!!!!!! Define the class CComplex.cpp for working with complex numbers, in such a way that the standard arithmetic and relational operators are overloaded for objects of this class. Additionally, overload the standard input and the standard output operators for this class.
// PROG0502.CPP - Overloading of Operators. Complex Numbers
#include <iostream>
using namespace std;
/////////////////////////////////////////////////////////////////
class CComplex
{
private:
double real, imag;
public:
CComplex( double r = 0, double i = 0 )
{
real = r;
imag = i;
}
double GetReal() const { return real; }
double GetImag() const { return imag; }
void AssignComplex( double r, double i )
{
real = r;
imag = i;
}
friend CComplex operator+( const CComplex & ,const CComplex &);
CComplex operator-( CComplex x );
};
/*
CComplex CComplex::operator+( CComplex x )
{
return CComplex( real + x.real, imag + x.imag );
}
*/
CComplex operator+( const CComplex &c1, const CComplex &c2 )
{
return CComplex( c1.real + c2.real, c1.imag + c2.imag );
}
CComplex CComplex::operator-( CComplex x )
{
return CComplex( real - x.real, imag - x.imag );
}
/////////////////////////////////////////////////////////////////
// App
void show( const CComplex & );
int main()
{
CComplex a, b, c(1.5, 2), d;
double re, im;
cout << "Complex number - insert re im: ";
cin >> re >> im;
a.AssignComplex( re, im );
b = a;
d = a + b - c;
d = d + CComplex(3, 3);
show( d );
show( a );
system("pause");
return 0;
}
// Visualizar un Complex
void show( const CComplex &c )
{
cout << "(" << c.GetReal() << ", ";
cout << c.GetImag() << ")" << endl;
}