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

I need help writing a program that finds the midpoint, length and also i do not

ID: 3558067 • Letter: I

Question

I need help writing a program that finds the midpoint, length and also i do not know how to place the red dots on the end and center of the line and I also need help displaying the info below a yellow line. I need my program to look like the picture i uploaded so far this is what i have:


#include <iostream>
#include "graph1.h"
#include <cmath>
using namespace std;

int main()
{
   //declare the X and Y variables
   int x1=0;
   int y1=0;
   int x2=0;
   int y2=0;
  

   //declare graphics window
   displayGraphics();
  

   //Declare point 1 of the line
   cout<< "Enter the X and Y coordinates for the point:";
   cin>>x1>>y1;

   //Declare point 2 of the line
   cout<< "Enter the X and Y coordinates for the second point:";
   cin>>x2>>y2;

   //declare line segment
   drawLine(x1,y1,x2,y2,1);

   //formula for length of line
   double length=0;
   length=sqrt( pow(x1-x2,2.0)+ pow(y1-y2,2.0));
   cout<< "Length of line is:"<<length<<endl;

       //formula for midpoint of line
   double midpoint1=0;
   double midpoint2=0;
   midpoint1 = ((x1+x2)/2);
   midpoint2= ((y1+y2)/2);
   cout << "The midpoint for this line is:"<< midpoint1<< midpoint2<<"."<<endl;

  
   //Drawing the yellow line
   int x3=0;
   int y3=400;
   int x4=639;
   int y4=400;
   int width2=1;

   drawLine(x3,y3,x4,y4,width2);
  

Explanation / Answer

Here's the revised code:

//This program is a start to solve basic coordinatre plane distances and midpoints
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

double x1 ;
double y1 ;
double x2 ;
double y2 ;
double midpointy ;
double midpointx ;

double distancefunction(double distance)
{
double distancex ;
double distancey ;
distancex = (x2 - x1) * (x2 - x1) ;
distancey = (y2 - y1) * (y2 - y1) ;
distance = distancex + distancey ;

return distance ;
}


int main(int nNumberofArgs, char* pzArgs[])
{
cout << "This is a calculator to find distance and the midpoint between two points. " ;
cout << "( " ;
cin >> x1 ;
cout << ", " ;
cin >> y1 ;
cout << ") " ;
cout << "( " ;
cin >> x2 ;
cout << ", " ;
cin >> y2 ;
cout << ") " ;

midpointx = (x1 + x2) / 2 ;
midpointy = (y1 + y2) / 2 ;


cout << " Midpoint: " << midpointx << "," << midpointy << endl ;
cout<< " Distance: SQRT: " << distancefunction << endl ;
system ("PAUSE") ;
}