answersLogoWhite

0

#include<iostream>

struct point

{

int x;

int y;

point (const int _x, const int _y): x {_x}, y {_y} {}

double distance (const point&) const;

};

double point::distance (const point& p) const

{

int w = x - p.x;

int h = y - p.y;

return sqrt (h*h + w*w);

}

std::ostream& operator<< (std::ostream& os, const point& p)

{

return os << '{' << p.x << ", " << p.y << '}';

}

int main()

{

using namespace std;

point a {5,10};

point b {7,2};

double d = a.distance (b);

std::cout << "The distance between coordinates " << a << " and " << b << " is " << d << ".\n" << std::endl;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What is the relationshjip between a computer program and an algorithm?

A computer program can use a pre-programmed Algorith to calculate what you want it to calculate.


What is the current distance planet Saturn is from earth?

Because the Earth and Saturn both orbit the Sun, the distance between Earth and Saturn varies constantly. I use the Stellarium program to calculate the distance; as of 12:45 PM PDT on April 5, 2009 it is 8.514366 AU.


The distance between two cities in km is input through the keyboard write a program to convert and print this distance in meters feet inches and centimeters?

mesh's basic salary is input through the keyboard. his dearness allowance is 40% of basic salarying , and house rent allowance is 20% of basic salaried. write a program to calculate his gross salary


What is the implementation of the distance function in C for calculating the distance between two points in a program?

To implement the distance function in C for calculating the distance between two points in a program, you can use the formula for Euclidean distance: double distance sqrt(pow((x2 - x1), 2) pow((y2 - y1), 2)); This formula calculates the distance between two points (x1, y1) and (x2, y2) in a Cartesian coordinate system.


When coordinates going into a program are specified relative to the program zero point it is called?

rapid


What is a computer program that coordinates all the activities of a computer hardware?

An operating system coordinates the activities of computer hardware


What program coordinates activities of computer hardware?

Operating system


Who coordinates with the Program OPR on all aspects of the function's MIC program and reports on improvements and weaknesses?

Functional OPR


Is there a free astronomy program that will calculate the distances between earth and other planets each day throughout different years?

Not too sure if there is a free program that will do the task automatically. However, Stellarium [See related link] is a free program that will give you the distance to any planet, or star from Earth - or any other planet that you choose. _____________________________ The open-source Stellarium program is one of the best tools for this, and I highly recommend it.


The local emergency program manager coordinates?

The local emergency management programs


What is the distances between the earth and the others planets in kilometers?

Because all of the planets are orbiting the SUN, the distance between Earth and the other planets are always changing. Take Venus, for example. Right now, Venus is between the Sun and Earth, so the distance to Venus is only about 40 million miles. In about 8 months, when Venus is on the other side of the Sun from us, the distance will be more like 130 million miles. There is a free planetarium program called Stellarium that you can download and install, which will allow you to calculate the distance from Earth to any other planet or moon.


When was Mesa Distance Learning Program created?

Mesa Distance Learning Program was created in 1999.