For the first one, it's well know that
(Y - Yp) / (X - XP) = (Yq - Yp) / (Xq - Xp)
so if you try to write the above formula in the form of y = ax + b you get the following
y = ( (Yq - Yp) / (Xq - Xp) ) * x + ( ( (Xq - Xp) * Yp + (Yp - Yq) * Xp ) / (Xq - Xp) )
Just wrote it, make sure it's correct. It involves some basic manipulation.
To calculate a and b just map them to their respective in the above equation and you get:
a = (Yq - Yp) / (Xq - Xp)
b = ( (Xq - Xp) * Yp + (Yp - Yq) * Xp ) / (Xq - Xp)
# EDIT: just a small note, that's the generic formula I mentioned, you can easily simplify the b formula and get the following:
b = Yp - a*Xp
So if you have P (1, 2) and Q (2, 4), notice that Q coordinates are double of P, it's expected to get y = 2x where a = 2 and b = 0 which you can calculate with what's mentioned above.
For the second one, you have 2 lines which results in 2 linear equations where you have a and b obviously. If you have 2 equations with a and b given, you can find x and y easily because the interception point is where they both have the same y and x.
so if you set y1 = y2, you get a1 * x + b1 = a2 * x + b2 and you solve for x where you get something like:
(a1 - a2) * x = b2 - b1
x = (b2 - b1) / (a1 - a2)
you find x then you replace the value of x in any equation you have to calculate the value of y.