design a class Line that implements a line, which is represented by the formula
ID: 3650212 • Letter: D
Question
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 throw an exception Parallel. 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.Explanation / Answer
#include #include #include #include class lines { private: int length,x1,y1,x2,y2,x,y,dx,dy,wx,wy,w,width; public: lines(); //Constructor void showline(); int sign(int); }; int lines::sign(int xx) { if(xx0) return 1; return 0; } lines::lines() { x=0;y=0; coutx1>>y1; coutx2>>y2; coutwidth; } void lines::showline() { char *s; int s1,s2,ic; float temp; x=x1;y=1; w=width; if(y2-y1) wx=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(y2-y1)); if(x2-x1) wy=((w-1)/2)*(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))/abs(x2-x1)); dx=abs(x2-x1); dy=abs(y2-y1); s1=sign(x2-x1); s2=sign(y2-y1); if(dy>dx) wy=wx; if(dy>dx) { temp=dy; dy=dx; dx=temp; ic=1; } else ic=0; float d=2*dy-dx; setcolor(0); for(int i=1;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.