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

const double PI = 3.14159265358979323846;

class ComplexTrigonometric {
private:
    double modulus, angle; // модуль и угол в градусах
    
public:
    void input() {
        cout << "Введите модуль: ";
        cin >> modulus;
        cout << "Введите угол в градусах: ";
        cin >> angle;
    }
    
    void output() {
        cout << "Комплексное число: " << modulus << "·(cos(" << angle << "°) + i·sin(" << angle << "°))" << endl;
    }
    
    ComplexTrigonometric add(ComplexTrigonometric other) {
        double angle1_rad = angle * PI / 180.0;
        double angle2_rad = other.angle * PI / 180.0;
        
        double real1 = modulus * cos(angle1_rad);
        double imag1 = modulus * sin(angle1_rad);
        double real2 = other.modulus * cos(angle2_rad);
        double imag2 = other.modulus * sin(angle2_rad);
        
        double real_sum = real1 + real2;
        double imag_sum = imag1 + imag2;
        
        ComplexTrigonometric result;
        result.modulus = sqrt(real_sum * real_sum + imag_sum * imag_sum);
        result.angle = atan2(imag_sum, real_sum) * 180.0 / PI;
        return result;
    }
    
    ComplexTrigonometric multiply(ComplexTrigonometric other) {
        ComplexTrigonometric result;
        result.modulus = modulus * other.modulus;
        result.angle = angle + other.angle;
        return result;
    }
    
    ComplexTrigonometric power(int n) {
        ComplexTrigonometric result;
        result.modulus = pow(modulus, n);
        result.angle = angle * n;
        return result;
    }
};

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