(Distance Between Points) Write function distance that calculates the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double.

What will be an ideal response?


```
// Calculate distance between 2 points.
#include
#include
#include
using namespace std;

double distance( double, double, double, double ); // function prototype

int main()
{
double x1; // x coordinate of first point
double y1; // y coordinate of first point
double x2; // x coordinate of second point
double y2; // y coordinate of second point

// prompt for first point coordinates
cout << "Enter the first point: ";
cin >> x1 >> y1;

// prompt for second point coordinates
cout << "Enter the second point: ";
cin >> x2 >> y2;

// calculate and display distance
cout << fixed << "Distance between (" << setprecision( 1 ) << x1
<< ", " << y1 << ") and (" << x2 << ", " << y2 << ") is "
<< distance( x1, y1, x2, y2 ) << endl;
} // end main
// distance calculates distance between 2 points
// given by (a1, b1) and (a2, b2)
double distance( double a1, double b1, double a2, double b2 )
{
return sqrt( pow( a1 - a2, 2 ) + pow( b1 - b2, 2 ) );
} // end function distance
```

Computer Science & Information Technology

You might also like to view...

Match the following terms with their description:

I. XFD II. Range III. Value IV. Semi-selection V. Text A. A measurable amount B. Also called pointing C. The last possible column in a worksheet D. A combination of letters not used in calculations E. A group of cells selected at the same time

Computer Science & Information Technology

The Word 2013 feature that displays when you point to the edge of a column or row gridline, enabling you to insert rows or columns is called the:

A) Border Painter. B) argument. C) insert control. D) Table Select indicator.

Computer Science & Information Technology

A security ____ is an outline of the overall information security strategy and a roadmap for planned changes to the organization's information security environment.

A. policy B. blueprint C. standard D. framework

Computer Science & Information Technology

A mobile device is freezing almost daily. The device remains powered on and the screen illuminated. The user restarts the device, and it operates for another day or so. This problem has been occurring for several weeks.   Which of the following steps should the user take next to resolve this issue?

A. Check for OS updates. B. Factory reset the device. C. Delete all user data. D. Return the device to the manufacturer.

Computer Science & Information Technology