#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

string solve_equation(double a, double b, double c) {
    cout << "Solving: " << a << "x² + " << b << "x + " << c << " = 0" << endl;
    
    // Linear equation (a = 0)
    if (a == 0) {
        if (b == 0) {
            return (c == 0) ? "Infinite solutions" : "No solution";
        } else {
            double x = -c / b;
            return "Linear equation: x = " + to_string(x);
        }
    }
    
    // Quadratic equation
    double discriminant = b*b - 4*a*c;
    cout << "Discriminant = " << discriminant << endl;
    
    if (discriminant > 0) {
        double x1 = (-b + sqrt(discriminant)) / (2*a);
        double x2 = (-b - sqrt(discriminant)) / (2*a);
        return "Two real roots: x₁ = " + to_string(x1) + ", x₂ = " + to_string(x2);
    } else if (discriminant == 0) {
        double x = -b / (2*a);
        return "One real root: x = " + to_string(x);
    } else {
        double real_part = -b / (2*a);
        double imag_part = sqrt(-discriminant) / (2*a);
        return "Complex roots: x₁ = " + to_string(real_part) + " + " + to_string(imag_part) + "i, x₂ = " + to_string(real_part) + " - " + to_string(imag_part) + "i";
    }
}

int main() {
    // Test cases
    double test_cases[6][3] = {
        {1, -3, 2},   // Two real roots
        {1, 2, 1},    // One real root
        {1, 0, 1},    // Complex roots
        {0, 2, -4},   // Linear equation
        {0, 0, 0},    // Infinite solutions
        {0, 0, 5}     // No solution
    };
    
    cout << "=== C++ EQUATION SOLVER ===" << endl;
    for (int i = 0; i < 6; i++) {
        cout << "\nTest case " << (i + 1) << ":" << endl;
        string result = solve_equation(test_cases[i][0], test_cases[i][1], test_cases[i][2]);
        cout << result << endl;
    }
    
    return 0;
}
