question archive Representing a point in the plane, a class named PlanePoint has Two data members i
Subject:Computer SciencePrice:4.89 Bought3
Representing a point in the plane, a class named PlanePoint has
Derive a class named SpacePoint to imagine a point in a three-dimensional space and has following additional features:
Implement both the classes and in the main() create two points with different dimensions and invoke appropriate function to display the distance between these two points.

#include<bits/stdc++.h>
using namespace std;
class PlanePoint
{
public:
int x;
int y;
int getX()
{
return x;
}
int getY()
{
return y;
}
double planeDistance(PlanePoint p1,PlanePoint p2)
{
//finding (x1-x2)^2 + (y1-y2)^2
double distance= (p1.getX()-p2.getX())*(p1.getX()-p2.getX()) + (p1.getY()-p2.getY())*(p1.getY()-p2.getY());
//finding square root of (x1-x2)^2 + (y1-y2)^2 and return distance
distance=sqrt(distance);
return distance;
}
};
class SpacePoint:public PlanePoint
{
public:
int z;
SpacePoint()
{
x=0;
y=0;
z=0;
}
SpacePoint(int X,int Y,int Z)
{
x=X;
y=Y;
z=Z;
}
int getZ()
{
return z;
}
//finding (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2
double spaceDistance(SpacePoint p1,SpacePoint p2)
{
double distance= (p1.getX()-p2.getX())*(p1.getX()-p2.getX()) + (p1.getY()-p2.getY())*(p1.getY()-p2.getY()) + (p1.getZ()-p2.getZ())*(p1.getZ()-p2.getZ());
//fincding square root of (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2
distance=sqrt(distance);
return distance;
}
};
int main()
{
cout<<"---------------Plane Point-------------------"<<endl;
//create object as point p1 and p2
PlanePoint p1;
PlanePoint p2;
//initialize value of oint p1 and p2
p1.x=5;
p1.y=7;
p2.x=10;
p2.y=15;
//print points
cout<<"x1="<<p1.getX()<<endl;
cout<<"y1="<<p1.getY()<<endl;
cout<<"x2="<<p2.getX()<<endl;
cout<<"y2="<<p2.getY()<<endl;
//print distance by callinfg function
cout<<"Distance between Point P1 and P2: "<<p1.planeDistance(p1,p2)<<endl;
cout<<"\n---------------Space Point-------------------"<<endl;
//creating object for space point s1 and s2
SpacePoint s1;
SpacePoint s2;
//initialize point value by s1 and s2
s1.x=4;
s1.y=7;
s1.z=10;
s2.x=15;
s2.y=20;
s2.z=30;
//print points
cout<<"x1="<<s1.getX()<<endl;
cout<<"y1="<<s1.getY()<<endl;
cout<<"z1="<<s1.getZ()<<endl;
cout<<"x2="<<s2.getX()<<endl;
cout<<"y2="<<s2.getY()<<endl;
cout<<"z1="<<s2.getZ()<<endl;
//print distance between space points s1 and s2
cout<<"Distance between Space Point s1 and s2: "<<s1.spaceDistance(s1,s2)<<endl;
return 0;
}
pleaes see the attached file for the complete solution.

