#include <iostream>
class RectangularForm {
private:
double real_part;
double imaginary_part;
public:
RectangularForm(double real, double imaginary) : real_part(real), imaginary_part(imaginary) {}
double getRealPart() const {
return real_part;
}
double getImaginaryPart() const {
return imaginary_part;
}
RectangularForm operator+(const RectangularForm& other) const {
return RectangularForm(real_part + other.real_part, imaginary_part + other.imaginary_part);
}
RectangularForm operator-(const RectangularForm& other) const {
return RectangularForm(real_part - other.real_part, imaginary_part - other.imaginary_part);
}
RectangularForm operator*(const RectangularForm& other) const {
double result_real = (real_part other.real_part) - (imaginary_part other.imaginary_part);
double result_imaginary = (real_part other.imaginary_part) + (imaginary_part other.real_part);
return RectangularForm(result_real, result_imaginary);
}
RectangularForm operator/(const RectangularForm& other) const {
double denominator = (other.real_part other.real_part) + (other.imaginary_part other.imaginary_part);
double result_real = ((real_part other.real_part) + (imaginary_part other.imaginary_part)) / denominator;
double result_imaginary = ((imaginary_part other.real_part) - (real_part other.imaginary_part)) / denominator;
return RectangularForm(result_real, result_imaginary);
}
void display() const {
std::cout << "Real Part: " << real_part << ", Imaginary Part: " << imaginary_part << std::endl;
}
};
int main() {
RectangularForm complex1(3.0, 4.0);
RectangularForm complex2(1.0, 2.0);
RectangularForm sum = complex1 + complex2;
sum.display();
RectangularForm difference = complex1 - complex2;
difference.display();
RectangularForm product = complex1 * complex2;
product.display();
RectangularForm quotient = complex1 / complex2;
quotient.display();
return 0;
}