Saturday, 9 March 2019

CPP-EX24


Manipulates user input of coordinates to calculate distance between two points on a 2D plane.

#include <iostream.h>
#include <math.h>
#include<conio.h>


void main()

{
            //Variable declarations
            double x1, y1, x2, y2;
            clrscr();
            //Output to prompt user to input an x and y coordinate
            cout << "Please enter and a point on a two dimensional graph, x coordinate first." << endl;
            cin >> x1 >> y1;

           
            cout << "Please enter another point on the graph, x coordinate first." << endl;
            cin >> x2 >> y2;



            cout << "You have entered the coordinates for the points: (" << x1 << "," << y1 << ")" <<  " and (" << x2 << "," << y2 << ")" << endl;

            double d, x0, y0;
            x0 = (x2-x1)*(x2-x1);
            y0 = (y2-y1)*(y2-y1);
            d = sqrt (x0 + y0);


      cout<<x0;
      cout<<y0;
            cout << "The distance between the points you entered is: " << d << endl;
            getch();
}