Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a class representing a point in 2D space with methods to calculate the distance from another point.

Hard

Problem Statement

Create a class representing a point in 2D space with methods to calculate the distance from another point.

Sample Input

Point p1(3, 4); Point p2(6, 8);

Sample Output

Distance between points: 5

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <cmath> #include <iostream> class Point { private: int x, y; public: Point(int xCoord, int yCoord); double distance(Point p); }; int main() { // Logic to demonstrate distance calculation return 0; }
Log in or sign up to run or submit your code.Log inSign up
Input
Point p1(3, 4); Point p2(6, 8);
Expected Output
Distance between points: 5