Write a program that asks the user the slope and y-intersect of one line y = a_1
ID: 3883844 • Letter: W
Question
Write a program that asks the user the slope and y-intersect of one line y = a_1x + b_1, the slope and y-intersect of a second line y = a_2x + b_2. The program returns the point of intersection of the two lines, if it exists. Otherwise, the program must print a message to indicate that the two lines do not have a point of intersection. Recall that, if it exists, the point of intersection (x_o, y_o) of two lines y = a_1x + b_1 and y = a_2x + b_2 is such that x_o = b_2 - b_1/a_1 - a_2 and Also, recall that two lines are parallel (and thus do not intersect) if they have the same slope. For this program you may choose your own user prompt and printed messages.Explanation / Answer
Program is in C++
#include<iostream>
using namespace std;
main()
{
float a1,a2,b1,b2;
cout<<"Enter slope and y intersect of line1";
cin>>a1>>b1;
cout<<"Enter slope and y intersect of line 2";
cin>>a2>>b2;
if(a1==a2) //checking if lines are parallel
cout<<"Line are parallel and they wont intersect"
else
{
cout<<"They will intersect at"
x=( ( b2 - b1) / ( a1 - a2 ));
y = a1*x+b1;
cout<<x<<" "<<y;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.