/* * Write a program called points.cc that: * * 1. Repeatedly reads in from the user the coordinates of two points: * (x1, y1) and (x2, y2) * 2. Calls a function that calculates and returns the distance between * the two points * 3. Prints out the distance calculated * 4. Exits when the points entered are (0, 0) and (0, 0) * * Note: The distance between two points (x1, y1) and (x2, y2) can be * calculated by taking the square root of [ (x2 - x1)^2 + (y2 - y1)^2 ] * where ^ means "to the power of" * * For example: * * Enter x1 and y1: * 0 0 * Enter x2 and y2: * 1 1 * The distance between the two points is 1.41421 * Enter x1 and y1: * 0 0 * Enter x2 and y2: * 3 4 * The distance between the two points is 5 * Enter x1 and y1: * 0 0 * Enter x2 and y2: * 0 0 */ #include #include using namespace std; float d(int, int, int, int); int main() { int x1, y1, x2, y2; float z; cout << "Enter x1 and y1:" << endl; cin >> x1 >> y1; cout << "Enter x2 and y2:" << endl; cin >> x2 >> y2; while (!((x1 == 0) && (y1 == 0) && (x2 == 0) && (y2 == 0))) { z = d(x1, y1, x2, y2); cout << "The distance between the two points is " << z << endl; cout << "Enter x1 and y1:" << endl; cin >> x1 >> y1; cout << "Enter x2 and y2:" << endl; cin >> x2 >> y2; } return (0); } float d(int x1, int y1, int x2, int y2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); }