Question: 4 . ( 4 pts ) A line in two dimensional space may be defined using two points ( x 1 , y 1 )

4.(4 pts) A line in two dimensional space may be defined using two points (x1,y1) and (x2,y2) where x1, y1, x2 and y2 are real numbers. If y1= y2, then it is a horizontal line, and if x1= x2, then it is a vertical line. If the line is not vertical, then the slope of the line is (y2-y1)/(x2-x1). The slope of a vertical line is \infty (undefined). Two lines are parallel if they have the same slope or if both are vertical lines. Design and implement the LineType class to represent a line as follows: A. Implement a class (or struct) called Point to represent a point (x,y). The x and y members may be public. You may nest the declaration of Point inside of LineType, but it is not required. B. Implement a class called LineType to represent a line. The only member variables should be two variables of type Point. Include the following functions in your LineType class: a 4-argument constructor that takes four values to specify the 2 points (you may assume the provided values will yield two different points). isHorizontal to return true if the line is horizontal, false otherwise. isVertical to return true if the line is vertical, false otherwise. slope to compute and return the slope (for non-vertical lines). parallel to return true if the line is parallel to another line, false otherwise. It is ok for slope to cause a runtime error if the line is vertical. It is NOT ok for parallel to cause a runtime error.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!