Добавил:
Рад, если кому-то помог Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
0
Добавлен:
01.11.2025
Размер:
2.39 Кб
Скачать
#include <iostream>
#include <cmath>
#include <windows.h>
using namespace std;

class ComplexAlgebraic {
private:
    double real, imag;
    
public:
    void input() {
        cout << "Введите действительную часть: ";
        cin >> real;
        cout << "Введите мнимую часть: ";
        cin >> imag;
    }
    
    void output() {
        cout << "Комплексное число: " << real;
        if (imag >= 0) cout << " + " << imag << "i";
        else cout << " - " << -imag << "i";
        cout << endl;
    }
    
    ComplexAlgebraic add(ComplexAlgebraic other) {
        ComplexAlgebraic result;
        result.real = real + other.real;
        result.imag = imag + other.imag;
        return result;
    }
    
    ComplexAlgebraic multiply(ComplexAlgebraic other) {
        ComplexAlgebraic result;
        result.real = real * other.real - imag * other.imag;
        result.imag = real * other.imag + imag * other.real;
        return result;
    }
    
    ComplexAlgebraic power(int n) {
        ComplexAlgebraic result;
        result.real = 1;
        result.imag = 0;
        
        for (int i = 0; i < n; i++) {
            double temp_real = result.real * real - result.imag * imag;
            double temp_imag = result.real * imag + result.imag * real;
            result.real = temp_real;
            result.imag = temp_imag;
        }
        return result;
    }
};

int main() {
    SetConsoleOutputCP(65001);
    
    ComplexAlgebraic c1, c2;
    cout << "=== Работа с комплексными числами ===" << endl;
    cout << "Введите первое комплексное число:" << endl;
    c1.input();
    cout << "Введите второе комплексное число:" << endl;
    c2.input();
    
    cout << "\nРезультаты:" << endl;
    cout << "Первое число: "; c1.output();
    cout << "Второе число: "; c2.output();
    
    ComplexAlgebraic sum = c1.add(c2);
    cout << "Сумма: "; sum.output();
    
    ComplexAlgebraic product = c1.multiply(c2);
    cout << "Произведение: "; product.output();
    
    ComplexAlgebraic power = c1.power(3);
    cout << "Первое число в степени 3: "; power.output();
    
    return 0;
}
Соседние файлы в папке Лаба1