Question: C + + pls; the MyPoint class was created to model a point in a two - dimensional space. The MyPoint class has the properties

C++ pls;
the MyPoint class was created to model a point in a two-dimensional space. The MyPoint class has the properties x and y that represent x- and y-coordinates, two get functions for x and y, and the function for returning the distance between two points. Create a class named ThreeDPoint to model a point in a three-dimensional space. Let ThreeDPoint be derived from MyPoint with the following additional features:
A data field named z that represents the z-coordinate.
A no-arg constructor that constructs a point with coordinates (0,0,0).
A constructor that constructs a point with three specified coordinates.
A constant get function that returns the z value.
A constant distance(const MyPoint&) function to return the distance between this point and the other point in the three-dimensional space.
Implement the classes. Write a test program that creates two points (0,0,0) and (10,30,25.5) and displays the distance between them.
When you create a new submission, you'll notice a template code. Your task is to fill in the missing code parts indicated by "your code here".
#include
#include
using namespace std;
class MyPoint
{
private:
double x;
double y;
public:
MyPoint()
{
x = y =0;
}
MyPoint(double x, double y)
{
this->x = x;
this->y = y;
}
double distance(const MyPoint& p2) const
{
return sqrt((x - p2.x)*(x - p2.x)+(y - p2.y)*(y - p2.y));
}
double getX() const
{
return x;
}
double getY() const
{
return y;
}
};
class ThreeDPoint: public MyPoint
{
private:
double z;
public:
ThreeDPoint();
ThreeDPoint(double x, double y, double z);
double getZ() const;
double distance(const ThreeDPoint& p2);
};
// Write your code here to implement the constructors and functions in ThreePoint
int main()
{
// Write your code here in the main function
return 0;
}

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 Programming Questions!