#include <iostream>
#include <string>
using namespace std;

class line
{
public:
    line() { setValues(); };    // default constructor which calls setValues()
    line(const line &n) :a(n.a), b(n.b), c(n.c){}; // copy constructor
    void setValues();           // prompts users to input coefficients
    void printEquation();       // print the equation
    friend void calIntersection(line &l1, line &l2); // calculate the intersection of two lines
private:
    double a, b, c;
};

void line::setValues()
{
    cout << "input a = ";
    cin >> a;
    cout << "input b = ";
    cin >> b;
    cout << "input c = ";
    cin >> c;

    if (a == 0 && b == 0)
        throw string("invalid equation");
}

void line::printEquation()
{
    cout << a << "x + " << b << "y + " << c << " = 0" << endl;
}

void calIntersection(line &n1, line &n2)
{
    if (n1.a == n2.a && n1.b == n2.b){
        if (n1.c == n2.c)
            throw string("same lines");
        else
            throw string("parallel lines");
    }

    double x = (n1.c * n2.b - n2.c * n1.b) / (n2.a * n1.b - n1.a * n2.b);
    double y = (n1.c * n2.a - n2.c * n1.a) / (n2.b * n1.a - n1.b * n2.a);
    cout << "coordinates of intersection = " << x << ", " << y << endl;
}

int main()
{
    try{
        line n1;
        n1.printEquation();

        line n2;
        n2.printEquation();

        calIntersection(n1, n2);
    }
    catch (const string& tip){
        cout << tip << endl;
    }
    return 0;
}