Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The equation of a line in standard form is ax + by c, wherein both a and b canno

ID: 3768054 • Letter: T

Question

The equation of a line in standard form is ax + by c, wherein both a and b cannot be zero, and a, b, and c are real numbers. If b 0, then-a/b is the slope of the line. Ifa 0, then it is a horizontal line, and f b 0, then it is a vertical line. The slope of a vertical line is undefined. Two lines are parallel if they have the same slope or both are vertical lines. Two lines are perpendicular if either one of the lines is horizontal and the other is vertical or the product of their slopes is-1. Design the class lineType to store a line. To store a line, you need to store the values of a (coefficient of a),b (coefficient of y), and c. Your class must contain the following operations a. If a line is nonvertical, then determine its slope b. Determine if two lines are equal. (Two lines apr + b-Y = c1 and a2x + b2 = c2 are equal if either al = a2, b1 b2, and q c2 or al = ka2. -kb2. and ke for some real number k.) . Determine if two lines are parallel. d. Determine if two lines are perpendicular. e. If two lines are not parallel, then find the point of intersection Add appropriate constructors to initialize variables of lineType. Also write a program to test your claSS Point of intersection means the point at which two lines intersect. These two lines are represented by the equation ax2+bx+c0 and apx+ bx+ c2 0 respectively. Given figure illustrate the point of intersection of two lines. ax+by 20 (x, y) We can find the point of intersection of three or more lines also. By solving the two equations, we can find the solution for point of intersection of two lines. The formula for point of intersection is b1C2 -b2c1 a1b2 a2b1' a2C1 -a1C2 a1b2 a2b

Explanation / Answer

#include <iostream>
using namespace std;
struct point
{
float x;
float y;
};
class line
{
private:
float a;
float b;
float c;
public :
line(float A, float B, float C)//constructor
{
a=A;
b=B;
c=C;
cout<<" line equation = ";
if(a!=0)
cout<<a<<"x";
if(b>0)
{
cout<<"+"<<b<<"y";
}
else if(b<0)
{
cout<<b<<"y";
}
if(c>0)
{
cout<<"+"<<c<<" = 0"<<endl;
}
else if(c<0)
{
cout<<c<<" = 0"<<endl;
}
else
{
cout<<" = 0"<<endl;
}
}
float slope()
{
return (-1*a)/b;
}
bool operator==(line other)
{
return ((a/other.a)==(b/other.b))&&((b/other.b)==(c/other.c));
}
bool is_parallel_to(line other)// return true if this line is parallel to other class
{
return ((a/other.a)==(b/other.b));
}
bool is_perpendicular_to(line other)// return true if this line is perpendicular to other class
{
return ((a*other.a + b*other.b)==0);
}
struct point point_of_intersection(line other)
{
struct point p;
float temp = (a*other.b - other.a*b);
p.x = (b*other.c - other.b*c)/temp;
p.y = (other.a*c - a*other.c)/temp;
return p;
}
float getA()
{
return a;
}
float getB()
{
return b;
}
float getC()
{
return c;
}
void setA(float A)
{
a=A;
}
void setB(float B)
{
b=B;
}
void setC(float C)
{
c=C;
}
};
int main()
{
line l1(1,2,3);
line l2(1,2,3);
line l3(1,2,7);
line l4(-2,1,8);
line l5(8,7,6);
struct point p;
if(l1.getB()!=0)
{
cout<<"The slope of the line = "<<l1.slope()<<endl;
}
else
{
cout<<" it is a vertical line"<<endl;
}
cout<<"checking equality of l1 & l2"<<endl;
if(l1==l2)
{
cout<<"two lines are equal"<<endl;
}
else
{
cout<<"two lines not equal"<<endl;
}
cout<<"checking equality of l1 & l3"<<endl;
if(l1==l3)
{
cout<<"two lines are equal"<<endl;
}
else
{
cout<<"two lines not equal"<<endl;
}
cout<<"checking l1 is parallel to l3 or not"<<endl;
if(l1.is_parallel_to(l3))
{
cout<<"l1 is parallel to l3"<<endl;
}
else
{
cout<<"l1 is not paralle to l3"<<endl;
}
cout<<"checking l1 is parallel to l4 or not"<<endl;
if(l1.is_parallel_to(l4))
{
cout<<"l1 is parallel to l4"<<endl;
}
else
{
cout<<"l1 is not parallel to l4"<<endl;
}
cout<<"checking l1 is perpendicular to l4 or not"<<endl;
if(l1.is_perpendicular_to(l4))
{
cout<<"l1 is perpendicular to l4"<<endl;
}
else
{
cout<<"l1 is not perpendicular to l5"<<endl;
}
cout<<"checking l1 is perpendicular to l4 or not"<<endl;
if(l1.is_perpendicular_to(l5))
{
cout<<"l1 is perpendicular to l5"<<endl;
}
else
{
cout<<"l1 is not perpendicular to l5"<<endl;
}
cout<<" finding intersection point for l1, l4"<<endl;
if(!l1.is_parallel_to(l4))
{
p = l1.point_of_intersection(l4);
cout<<"point of intersection = ( "<<p.x<<" , "<<p.y<<" )"<<endl;
}
else
{
cout<<"both lines are parellel"<<endl;
}
return 0;
}

output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote