Question: I am trying to write this program where the user enters two equations for two separate lines, and the program is supposed to return the
I am trying to write this program where the user enters two equations for two separate lines, and the program is supposed to return the point at which they intersect. However, I am having trouble getting the specific values of the string that then enter. By that I mean, I can get the string stored to a variable named "equation", but how do I get the value of the slope and the y-intercept from that?
Also, (if it helps) the line class I am using is as follows:
#include "LineClass.h"
Line::Line() { p1= Point(0,0); p2 = Point(1,1); } Line::Line(Point a, Point b) { p1 = Point(a.x,a.y); p2 = Point(b.x, b.y); } void Line::setFirstPoint(Point a) { p1=a; } void Line::setSecondPoint(Point a) { p2=a; } Point Line::getFirstPoint() const { return p1; } Point Line::getSecondPoint() const { return p2; } bool Line::slope (double& m) const { if ((p1.x-p2.x)==0) { return false; } else { m = (p1.y-p2.y)/(double)(p1.x-p2.x); return true; } } bool Line::yIntercept(double& b) const { double m; if (this -> slope(m)) { b = p1.y-m * p1.x; return true; } else { return false; } } bool Line::isParallel(Line l) const { double m1, m2; if(this->slope(m1) && l.slope(m2)) if(m1 == m2) { return true; } else { return false; } } bool Line::isCollinear(Line l) const { double slope1; double slope2; double b1; double b2; if(this->slope(slope1)&&l.slope(slope2)) { this->yIntercept(b1); l.yIntercept(b2); if (slope1==slope2 && b1==b2) { return true; } } else { return false; } } bool Line::isPerpendicular(Line l) const { double m1; double m2; if (this->slope(m1)&&l.slope(m2)) { if (-1/m1 == m2) return true; } else if (!this->slope(m1) && m2==0) { return true; } else if(m1==0 && !this->slope(m2)) { return true; } else { return false; } } Point Line::intersect(Line l) const { return p1; } void Line::display(ostream& out) const { double m; double b; this ->slope(m); this -> yIntercept(b); out
Below is the program assignment:

Program 24 odi Write a C program that: 1, reads two linear equations from standard input (cin) and 2if the two lines are parallel or collinear 1. print 'NO SOLUTION 3 if the two lines intersect 1. print "SOLUTION: (xy) note: x and y shouid be rounded two three decimal places HINT: Use the Line class you wrote for program 20 Sample Inputoutput edi INPUT y-59 y=-2x-11 OUTEUT SOLUTION: -2.857.-5.2861 INPUT y=-2x-11 OUTEU SOLUTION: (9.000,-29.0001 INPU Y-2x y2x 11 OUTEU NO SOLUTIO
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
