Design a class Line that implements a line, which is represented by the formula y = ax+b. Your class should store a and b as double member variables.
Write a member function intersect(L) that returns the x coordinate
at which this line intersects line L. If the two lines are parallel, then your
function should return a message " Parallel" and exit. Write a C++ program that creates a number of Line objects and tests each pair for intersection. Your program should print an appropriate error message for parallel lines.
1
Expert's answer
2016-02-10T00:01:18-0500
#include <iostream>
using namespace std;
class Line {
private: double a, b; public: Line(double a, double b){ this->a = a; this->b = b; }
int main() { Line line1(0, 0); Line line2(1, 1); Line line3(2, 2); Line line4(2, -2); Line array[] = {line1, line2, line3, line4}; int n = sizeof(array) / sizeof(*array);
Comments
Leave a comment