Код: Выделить всё
enter code hereКод: Выделить всё
#include
using namespace std;
#pragma once
class Complex {
private:
float real;
float imaginary;
public:
Complex() : real(0), imaginary(0) {}
Complex(float r, float i) : real(r), imaginary(i) {}
Complex operator+(Complex rhs) {
return Complex(this->real + rhs.real, this->imaginary + rhs.imaginary);
}
Complex operator-(Complex rhs) {
return Complex(this->real - rhs.real, this->imaginary - rhs.imaginary);
}
Complex operator*(const Complex& other) const {
float new_real = (this->real * other.real) - (this->imaginary * other.imaginary);
float new_imaginary = (this->real * other.imaginary) + (this->imaginary * other.real);
return Complex(new_real, new_imaginary);
}
Complex operator/(const Complex& other) const {
float denominator = (other.real * other.real) + (other.imaginary * other.imaginary);
float new_real = ((this->real * other.real) + (this->imaginary * other.imaginary)) / denominator;
float new_imaginary = ((this->imaginary * other.real) - (this->real * other.imaginary)) / denominator;
return Complex(new_real, new_imaginary);
}
// Function to find the conjugate of a complex number
Complex conjugate() {
return Complex(this->real, -(this->imaginary));
}
// A helper function to print the complex number
void print() const {
if (imaginary >= 0)
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79016239/c-not-being-in-input-twice[/url]