first git commit
This commit is contained in:
commit
bc84588bd1
49
1.cpp
Normal file
49
1.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
|
||||
class Complex {
|
||||
private:
|
||||
double real;
|
||||
double imag;
|
||||
|
||||
public:
|
||||
// Конструкторы
|
||||
Complex(double r = 0.0, double im = 0.0) : real(r), imag(im) {}
|
||||
|
||||
// Метод для получения комплексного сопряжения (унарный плюс)
|
||||
Complex operator+() const {
|
||||
return Complex(real, -imag);
|
||||
}
|
||||
|
||||
// Метод для умножения на действительное число
|
||||
Complex operator*(double scalar) const {
|
||||
return Complex(real * scalar, imag * scalar);
|
||||
}
|
||||
|
||||
// Метод для умножения на комплексное число
|
||||
Complex operator*(const Complex& other) const {
|
||||
return Complex(real * other.real - imag * other.imag,
|
||||
real * other.imag + imag * other.real);
|
||||
}
|
||||
|
||||
// Метод для вывода комплексного числа
|
||||
void display() const {
|
||||
std::cout << "(" << real << " + " << imag << "i)" << std::endl;
|
||||
}
|
||||
|
||||
// Дружественная функция для умножения действительного числа на комплексное число
|
||||
friend Complex operator*(double scalar, const Complex& c);
|
||||
};
|
||||
|
||||
// Реализация дружественной функции для умножения действительного числа на комплексное число
|
||||
Complex operator*(double scalar, const Complex& c) {
|
||||
return Complex(c.real * scalar, c.imag * scalar);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Пример использования операций
|
||||
Complex a(2.0, 3.0);
|
||||
Complex b = 2.5 * a; // Умножение действительного числа на комплексное число
|
||||
b.display(); // Ожидаем (5 + 7.5i)
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
Практическая работа 1.pdf
Normal file
BIN
Практическая работа 1.pdf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user