#include#include using namespace std; class Point { private: double x; double y; public: Point(double x, double y) { this->x = x; this->y = y; } double distance(Point p) { double dx = p.getX() - this->x; double dy = p.getY() - this->y; return sqrt(dx*dx + dy*dy); } double getX() { return this->x; } double getY() { return this->y; } }; int main() { Point p(3.0, 4.0); Point q(0.0, 0.0); double d = p.distance(q); cout << "Distance: " << d << endl; return 0; }
#includeDescription: This code creates a 3D point with x-coordinate 3.0, y-coordinate 4.0, and z-coordinate 5.0. It also creates another point at the origin (0, 0, 0). It calculates the distance between these two points using the distance formula, and outputs the result. Package Library: Standard C++ Library.#include using namespace std; class Point { private: double x; double y; double z; public: Point(double x, double y, double z) { this->x = x; this->y = y; this->z = z; } double distance(Point p) { double dx = p.getX() - this->x; double dy = p.getY() - this->y; double dz = p.getZ() - this->z; return sqrt(dx*dx + dy*dy + dz*dz); } double getX() { return this->x; } double getY() { return this->y; } double getZ() { return this->z; } }; int main() { Point p(3.0, 4.0, 5.0); Point q(0.0, 0.0, 0.0); double d = p.distance(q); cout << "Distance: " << d << endl; return 0; }