Computer scienceProgramming languagesC++Types and data structures

Structures

Theory

Point

Report a typo

Write a C++ program that defines a structure called Point with the following members: x (int) and y (int). Create two objects of the structure and initialize their members from input. Calculate and print the distance between the two points.

Distance Calculation Formula:

Distance = √((x2 - x1)² + (y2 - y1)²)

Here is a little explanation of the mathematical operations. You can just use the given expression.

float distance = std::sqrt(std::pow(X2 - X1, 2) + std::pow(Y2 - Y1, 2));

std::sqrt - taking the square root

std::pow - raising a number to the second power (squaring)

Output only the integer part of the distance!

Sample Input 1:

1 1 5 5

Sample Output 1:

5
Write a program in C++
#include <iostream>
#include <cmath>

Create a free account to access the full topic