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

//elearningquedugabbcsweb . e c e Error 401 xAn Introduction to Computer 4) The

ID: 3593459 • Letter: #

Question

//elearningquedugabbcsweb . e c e Error 401 xAn Introduction to Computer 4) The midpoint of the line joining two points A( B(x, y2) is172,112) and the distance between the two points is AB-V(x2-r)4(ya-yi) . y) and Write a C++ program that asks the user to enter the coordinates of the end points of a straight line and then output the coordinates of its midpoint together with thex distance between the two points.. Test your program using the coordinates of the following line: (-3,7) 7 0r-9-1) The non er p diss inated in a rector of resistance R whenennent none throe its men hv

Explanation / Answer

#include <iostream>

//Header file for pow function
#include <math.h>


using namespace std;

int main()
{
//Declare variables
  
int x1=0,y1=0,x2=0,y2=0,distance=0,midpoint1=0,midpoint2=0;
  
//Take input for starting point
  
cout<<"Enter x and y coordinates of starting point ";
cin>>x1;
cout<<" ";
cin>>y1;
  
//Take input for ending point
  
cout<<"Enter x and y coordinates of end point ";
cin>>x2;
cout<<" ";
cin>>y2;

//Calculate midpoint

midpoint1=(x1+x2)/2;
midpoint2=(y1+y2)/2;

//Display the midpoint
  
cout<<"The midpoint is(x,y) "<<midpoint1<<","<<midpoint2<<" ";

//Calculate the distance
  
distance=pow(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)),0.5);
  
//Display the distance
  
cout<<"The distance between two points is "<<distance<<" ";
return 0;
}