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

.In C++ Write the code that would be in the file Point2D.h for the class Point2D

ID: 3903459 • Letter: #

Question

.In C++

Write the code that would be in the file Point2D.h for the class Point2D. The

class should model a two

-

dimensional point (x, y), where x is the horizontal

component of the point and y is the vertical component of the point. The x

and y components of the point are the basic data for the class.

?The class should contain a default constructor that sets the x and

y components

to zero.

?The class should contain a constructor that takes values to assign to the x and y

components.

?The class should contain accessor and mutator functions for the x component of

the point. (NOTE: Remember the accessor functions are

the “get” functions,

while the mutator functions are the “set” functions.)

?The class should contain accessor and mutator functions for the y component of

the point.

?The class should contain a member function, Scale, that will scale x and y

components of the point by the scale value passed to the function Scale.

?The class should contain Read and Write functions.

?The Read function should be able to read from the keyboard or from a file.

?The Write function should be able to write to the monitor

or to a file.

Explanation / Answer

#include <iostream>

#include <string>

#include <fstream>

#include <math.h>

#include "Point2D.h"

#include "Point3D.h"

#include "Line2D.h"

using namespace std;

class Line3D : public Line2D

{

private:

Point3D pt1;

Point3D pt2;

protected:

void setLength();

public:

Line3D(Point3D, Point3D);

Point3D getPt1();

Point3D getPt2();

void setPt1(Point3D);

void setPt2(Point3D);

};

===========

Line3D.cpp

===========

#include "Line3D.h"

using namespace std;

Line3D::Line3D(Point3D point1, Point3D point2)

{

pt1 = point1;

pt2 = point2;

}

Point3D Line3D::getPt1()

{

return pt1;

}

Point3D Line3D::getPt2()

{

return pt2;

}

void Line3D::setPt1(Point3D SetPt1)

{

pt1 = SetPt1;

}

void Line3D::setPt2(Point3D SetPt2)

{

pt2 = SetPt2;

}

void Line3D::setLength()

{

length = sqrt (pow((pt1.getX() - pt2.getX()),2) + pow((pt1.getY() - pt2.getY()),2) + pow((pt1.getZ() - pt2.getZ()),2));

}