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

The instances A, B, C, D and E were created by saying: int minusfour = -4; int m

ID: 3771501 • Letter: T

Question

The instances A, B, C, D and E were created by saying:
int minusfour = -4;
int minusthree = -3;
int minustwo = -2;
int zero = 0;
int two = 2;
int four = 4;

Point A = Point( minusthree, two );
Point B = Point( zero, zerio );
Point C = Point( four, zero );
Point D = Point( minusfour, minustwo );
Point E = Point( zero, minusthree );


Each Point holds an x and y coordinate. For the constructors shown above, here is the class definition (.h)

Point();
Point( int & x, int & y );
Point( double & x, double & y );
double getX() const;
double getY() const;

double my_X, my_Y;


Based on the information shown here, a possible implementation (.cpp) for Point is shown below.

my_X = 0;
my_Y = 0;

my_X = x;
my_Y = y;

my_X = x;
my_Y = y;

return( my_X );

return( my_Y );

Line AB( A, B ); // A and B are declared as Point
Line CD(four, zero, minusfour, minustwo); // from C to D


In addition, make a member operation defined as:

double length();

for Line which calculates the length of the line. The length of a line from a starting point located (x1, y1) to an ending point located at (x2, y2) can be calculated by the following formula:


HINT: If you #include <cmath>, you can get the functions

double sqrt( double )
double pow( double, double )



As currently defined, can your implementation of Line::length() be marked const?

The instances A, B, C, D and E were created by saying:
int minusfour = -4;
int minusthree = -3;
int minustwo = -2;
int zero = 0;
int two = 2;
int four = 4;

Point A = Point( minusthree, two );
Point B = Point( zero, zerio );
Point C = Point( four, zero );
Point D = Point( minusfour, minustwo );
Point E = Point( zero, minusthree );

Explanation / Answer

/*
* Line.cpp
*
* Created on: 13-Dec-2015
*      Author: Ravi
*/

#include "Line.h"
#include <cmath>
#include <iostream>


using namespace std;

Line::Line(Point A, Point B) {
   // TODO Auto-generated constructor stub
   p1 = A;
   p2 = B;
}

Line::Line(int & x1, int & y1,int & x2, int & y2) {
   // TODO Auto-generated constructor stub
   p1 = Point(x1,y1);
   p2 = Point(x2,y2);
}

Line::Line(double & x1, double & y1, double & x2, double & y2) {
   // TODO Auto-generated constructor stub
   p1 = Point(x1,y1);
   p2 = Point(x2,y2);
}

Line::~Line() {
   // TODO Auto-generated destructor stub
}


double Line::length() {
   return sqrt( pow(p1.getX()-p2.getX(), 2)+ pow(p1.getY()-p2.getY(), 2));
}


void Line::display() {
   cout << " Point 1: (" << p1.getX() <<"," <<p1.getY() << ") Point 2: (" << p1.getX() <<"," <<p1.getY() << ") Distance: " << length() <<endl;
}
int main()
{
   int minusfour = -4;
   int minusthree = -3;
   int minustwo = -2;
   int zero = 0;
   int two = 2;
   int four = 4;

   Point A = Point( minusthree, two );
   Point B = Point( zero, zero);
   Point C = Point( four, zero );
   Point D = Point( minusfour, minustwo );
   Point E = Point( zero, minusthree );
   Line AB = Line ( A, B ); // A and B are declared as Point
   Line CD = Line(four, zero, minusfour, minustwo); // from C to D
   AB.display();
   CD.display();





   return 0;
}

--output----

Point 1: (-3,2) Point 2: (-3,2) Distance: 3.60555
Point 1: (4,0) Point 2: (4,0) Distance: 8.24621

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote