Question: Write a C++ class Segment, representing straight line segment between two coordinate points vl and v2. The two coordinate points are given by two vectors

 Write a C++ class Segment, representing straight line segment between two

Write a C++ class Segment, representing straight line segment between two coordinate points vl and v2. The two coordinate points are given by two vectors vl and v2 of type double. Each vector variable v1 and v2 contain two values, i.e. vl = (xl, yl), v2 = (x2, y2), of type double, representing the coordinates of each points through which the line segment passes. (1) A single class instance (or object instantiation) is generated as: Segment A(v1, v2). The name of this instances is A. Its arguments are vectors vi and v2, of type double, denoting coordinates points vi = (x1, y1), v2 = (x2, y2) through which the line segment passes. As an example of object instantiation, the following illustrates how two instances A and B of the object Segment are generated: Segment A[{1,2}, {3,4}) and Segment B(15,6}, {7,8}). (2) Write a public class member function show() which is called/used in the following way, illustrated here on the instance A: show(A). A call, show(A) returns a string "Line segment between points (1,2) and (3,4)." Similarly, for any other instance of the object Segment. (3) Write a public class member function getslope() which is called/used in the following way, illustrated here on the instance A: A.getSlope() A call, A.getSlope () returns the slope (as a double) of the line passing in through points (1,2) and (3,4). For simplicity, you may assume that none of the coordinates used will result in a infinite slope! (5) Write a public class member function getSegmentLength(), which is called by reference, illustrated here on the instance A: getSegmentLength(&A) When called, get Segment Length(&A) returns the length (as a double) of the line segment between points (1,2) and (3,4). (6) Write a public class member function getLonger Segment() which is called/used in the following way, illustrated here on the two instances A and B of the object: getLongerSegment (A, B) When called, getLonger Segment (A, B) returns the object instance with the longer segment. (7) Overload the + operator so that we can combine the instances of this object as illustrated here on the two instances A and B: A+B. The outcome of A+B must result in a new Segment object, whose elements have been combined coordinate-wise. For two instances AC{1,2}, {3,4}) and Segment B({5,6), 47,8}), the outcome of show(A+B) would result in "Line segment between points (6,8) and (10,12)

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!