Computing Distance Between Two Points using C++ - Prof. Thomas D. Walker, Study Guides, Projects, Research of Statistics

The code for a c++ program that calculates the distance between two points using the distance formula. The program declares and initializes variables, computes the sides of a right triangle, and prints the result.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 09/16/2008

timied07
timied07 🇺🇸

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
//@PID@HW#@
/*-----------------------------------------*/
/* Program chapter_1 */
/* */
/* This program computes the */
/* distance between two points. */
#include<iostream> // Required for cout. endl.
#include<cmath> // Required for sqrt()
using namespace std;
int main()
{
// Declare and initialize objects.
double x1(1), y1(5), x2(4), y2(7),
side1, side2, distance;
// Compute sides of a right triangle.
side1 = x2 - x1;
side2 = y2 - y1;
distance = sqrt(side1*side1 + side2*side2);
// Print distance.
cout << "The distance between the two points is "
<< distance << endl;
//Exit program.
return 0;
}
/*-----------------------------------------*/

Partial preview of the text

Download Computing Distance Between Two Points using C++ - Prof. Thomas D. Walker and more Study Guides, Projects, Research Statistics in PDF only on Docsity!

//@PID@HW#@

/* Program chapter_1 / / / / This program computes the / / distance between two points. / #include // Required for cout. endl. #include // Required for sqrt() using namespace std; int main() { // Declare and initialize objects. double x1(1), y1(5), x2(4), y2(7), side1, side2, distance; // Compute sides of a right triangle. side1 = x2 - x1; side2 = y2 - y1; distance = sqrt(side1side1 + side2side2); // Print distance. cout << "The distance between the two points is " << distance << endl; //Exit program. return 0; } /-----------------------------------------*/