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

Anybody please help me with this question.. thanks! Complex A complex nunber is

ID: 3813429 • Letter: A

Question

Anybody please help me with this question.. thanks!

Complex A complex nunber is any number a ba. where s is the real part, and b is the inag nary part The addition of two complex numbers is given as subtractio a +bi The nultiplication of twa complex The division of two complex a bi is Tiven a njuga required to define clas amed Complex for complex numbers The real part and Enaginary part are tw ctions mplex add (Complex variables Define five public x), complex subtract Complex x) complex multiply (Complex x), ex divide complex and complex c jugate so that we complex numbers You also define per forn the operatio other member functions, such as setting the value of a complex printing the complex number given The class Complex is declared in the file complex the ction is defined in the file lablotas k2.cpp You main ful given need to define the member functions of class complex in the file Complex opp You submit only the file Complex.cpp The output of the program is given below: he value of x1 is 1.2+2.3i The value of X2 is: 3.4+4.5i x3 X1 X2 4.6+6.8i x4 x1 X2 2.2-2.2i 5 x3 X2 14.96+43.82i x6 x3 x2 1.45363+0.0760767i hange x6 to its conjugate. 1.45363-0.87607 67i The new value of X6 is

Explanation / Answer

File Complex.h

class Complex
{
private:
double real;
double imaginary;
public:
Complex(double a, double b);
Complex();
  
Complex complex_add(Complex x);
Complex complex_subtract(Complex x);
Complex complex_multiply(Complex x);
Complex complex_divide(Complex x);
Complex complex_conjugate();
void print();
void setReal(double a);
void setImaginary(double b);
void setComplex(double a, double b);
  
};

// Complex.cpp

#include <iostream>
#include "Complex.h"
using namespace std;

Complex::Complex()
{
real = 0;
imaginary = 0;
}

Complex::Complex(double a, double b)
{
real = a;
imaginary = b;
}

Complex Complex::complex_add(Complex x)
{
Complex c = Complex(real, imaginary);
c.real = real + x.real;
c.imaginary = imaginary + x.imaginary;
return c;
}

Complex Complex::complex_subtract(Complex x)
{
Complex c = Complex(real, imaginary);
c.real = real - x.real;
c.imaginary = imaginary - x.imaginary;
return c;
}

Complex Complex::complex_multiply(Complex x)
{
Complex c = Complex(real, imaginary);
c.real = real*x.real - imaginary*x.imaginary;
c.imaginary = imaginary*x.real + real*x.imaginary;
return c;
}

Complex Complex::complex_conjugate()
{
Complex c = Complex(real, imaginary);
c.imaginary = -1*imaginary;
return c;
}

Complex Complex::complex_divide(Complex x)
{
Complex temp = x.complex_conjugate();
temp = complex_multiply(temp);
double norm = x.real*x.real + x.imaginary*x.imaginary;
temp.real = temp.real/norm;
temp.imaginary = temp.imaginary/norm;
return temp;
}

void Complex::print()
{
cout << real;
if (imaginary >= 0)
{
cout << "+";
}
  
cout << imaginary << "i";
}

void Complex::setReal(double a)
{
real = a;
}

void Complex::setImaginary(double b)
{
imaginary = b;
}

void Complex::setComplex(double a, double b)
{
setReal(a);
setImaginary(b);
}

// main.cpp

#include <iostream>
#include "Complex.h"

using namespace std;

int main()
{
Complex x1 = Complex(1.2, 2.3);
Complex x2 = Complex();
x2.setComplex(3.4, 4.5);
cout << "The value of x1 is: ";
x1.print();
cout << endl;
cout << "The value of x2 is: ";
x2.print();
cout << endl;

Complex x3 = x1.complex_add(x2);
cout << "x3 = x1 + x2 = ";
x3.print();
cout << endl;

Complex x4 = x1.complex_subtract(x2);
cout << "x4 = x1 - x2 = ";
x4.print();
cout << endl;

Complex x5 = x3.complex_multiply(x2);
cout << "x5 = x3 * x2 = ";
x5.print();
cout << endl;

Complex x6 = x3.complex_divide(x2);
cout << "x6 = x3 / x2 = ";
x6.print();
cout << endl;

cout << "Change x6 to its conjugate." << endl;
x6 = x6.complex_conjugate();
cout << "The new value of x6 is: ";
x6.print();
cout << endl;

return 0;
}

To compile

g++ main.cpp Complex.h Complex.cpp

to run

./a.out

The value of x1 is: 1.2+2.3i
The value of x2 is: 3.4+4.5i
x3 = x1 + x2 = 4.6+6.8i
x4 = x1 - x2 = -2.2-2.2i
x5 = x3 * x2 = -14.96+43.82i
x6 = x3 / x2 = 1.45363+0.0760767i
Change x6 to its conjugate.
The new value of x6 is: 1.45363-0.0760767i

Please rate question positivly if it answered your query. Please comment if any thing is not clear or need explaination.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote