Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

16. (30 pts) Line Segment with End Points (Parts a- d). Let\'s say we need to de

ID: 3735265 • Letter: 1

Question

16. (30 pts) Line Segment with End Points (Parts a- d). Let's say we need to design two classes, one named Point and one named LáneSegment. Each Point consists of two double precision numbers: a. (10 pts) Declare the Point class based on the description above. There are many operations attributes/data members should be private. The class should declare the following public xCoordinate, yCoordinate. A LineSegment is defined by two end Points that we could define for a Point, but we are only going to look at a subset for this problem. All member operations/functions only: i. (2 pts) A constructor that specifies two default arguments newxCoord and newCoord and sets both of them by default to 0 ii. (2 pts) A const function called getxCoord ) for getting the xCoordinate. ili. (2 pts) A const function called getYCoord ) for getting the yCoordinate. iv. (2 pts) A function called drawPoint ) for displaying to the screen the values of the coordinates in the format: (xCoordinate, yCoordinate). class Point public: II Should contain four prototypes/declarations po%) ( ) ; private: I/ Should contain two attributes I1 1 pt / data member doube

Explanation / Answer

16.

a.

class Point{

       public:

             Point(double newXCoord=0,double newYCoord=0);

            

             double getXCoord() const;

             double getYCoord() const;

             void drawPoint();

            

       private:

             double x,y;

};

Point:: Point(double newXCoord=0,double newYCoord=0)

{

       x = newXCoord;                  

y= newYCoord;

}

double Point:: getXCoord() const

{

       return x;

}

double Point:: getYCoord() const

{

       return x;

}

void Point::drawPoint()

{

cout<<"("<<x<<","<<y<<")";

}

b.

class LineSegment{

       public:

             ~LineSegment();

            

             LineSegment(const LineSegment &ls);

            

             double computeLength();

            

             // non-member function of LineSegment but can access private fields

             friend ostream & operator<<(ostream &dout, const LineSegment &ls);

       private:

             Point *pHead;

};

c.

double LineSegment:: computeLength()

             {

                    double length = sqrt(pow((pHead[0].getXCoord()-pHead[1].getXCoord()),2) - (pow((pHead[0].getYCoord() - pHead[1].getYCoord()),2)));

                    return length;

             }

d.

ostream& operator<<(ostream &dout, const LineSegment &ls)

{

       dout<<"("<<ls.pHead[0].getXCoord()<<","<<ls.pHead[0].getYCoord()<<") : "<<"("<<ls.pHead[0].getXCoord()<<","<<ls.pHead[0].getYCoord()<<")";

       return dout;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote