Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Input: 0,0 10,10 E 2y600kS Catalog HSteve 6.21 HW11-01: Distance between two poi

ID: 3723661 • Letter: I

Question


Input: 0,0 10,10
E 2y600kS Catalog HSteve 6.21 HW11-01: Distance between two points Given two points (x1, y1) and (x2, y2), the distance between this points is defined as the square root of (x2-x1)"2+ (y2-y1)*2. Write a function distance(x1,y1, x2, y2) that returns the distance between the given points. The main0 function is written for you; your job is to write the distance function. Start by reviewing the code for 'main.cpp which is visible in the editor pane-note that this code is read-only (you cannot modify it). Notice that the main0 program inputs two points (x1,y1) and (x2, y2), calls distance to compute the distance, and then outputs this result. Above the editor pane youll see the text 'Current file: main.cpp, with a little drop-down arrow to the right. Click the drop-down and select functions.cpp. Then, to avoid a bug in some web browsers, please immediately click the link "Load default template... You only need to do this once, the first time you view the file. Implement the function. To test your work in Develop mode, supply two points in the following format 0,0 10,10 Each point is on a line by itself, with no spaces, In this case the output should be Distance: 14.1421 When you are ready to submit for testing, switch to Submit mode and submit for grading. You have unlimited submissions 0/100 ACTIVITY 621.1: HW11-01: Distance between two points LAB Load default template. Current file: functions.cpp

Explanation / Answer

#include <bits/stdc++.h>

using namespace std;

// Function to calculate distance

float distance(int x1, int y1, int x2, int y2)

{

// Calculating distance

return sqrt(pow(x2 - x1, 2) +

pow(y2 - y1, 2) * 1.0);

}

// Drivers Code

int main()

{

int x1,x2,y1,y2;

cin >>x1;

cin>>y1;

cin>>x2;

cin>>y2;

cout << distance(x1,y1,x2,y2);

return 0;

}