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

In C++ ASAP The problem 1. Create a class called myPoint with x and y fields 2.

ID: 3755733 • Letter: I

Question

In C++

ASAP

The problem 1. Create a class called myPoint with x and y fields 2. Overload the >operator for the class to read a point in the format (x,y) a. E.g., (4.35, 6.87) should read 4.35 in the field x and 6.87 in the field y 3. 4. Create a class called myLine with two fields of type myPoint. Create a member function in myLine called getLength that computes the length of the line as follows: (xi -x2)2 + (yi - y2)2 if the end points are (xi,yi) and (x2,y2) 5. Overload >, overload 20 points 3. myLine class 10 points 4. getLength function 10 points 5. Operator > >,

Explanation / Answer

//myPoint.h

#include<iostream>

using namespace std;

class myPoint{

private:double x,y;

public:

friend istream & operator >> (istream &, myPoint &);

double getX();

double getY();

};

//myPoint.cpp

#include "myPoint.h"

double myPoint::getX(){

return x;}

double myPoint::getY(){

return y;}

istream & operator >> (istream &in, myPoint &p){

cout<<"Enter x : ";

in>>p.x;

cout<<"Enter y : ";

in>>p.y;

}

//myLine.h

#include "myPoint.cpp"

class myLine{

private: myPoint p1 , p2;

public:

myLine();

myLine(myPoint ,myPoint );

double getLength();

bool operator > (myLine );

bool operator < (myLine );

bool operator >= (myLine );

bool operator <= (myLine );

double slope();

double intercept();

};

//myLine.cpp

#include "myLine.h"

#include <math.h>

myLine::myLine(){

}

myLine::myLine(myPoint a ,myPoint b){

p1=a;

p2=b;

}

double myLine::getLength(){

return sqrt(pow(p1.getX()-p2.getX(),2)+pow(p1.getY()-p2.getY(),2));

}

bool myLine::operator > (myLine l){

if(this->getLength()>l.getLength())return true;

return false;

}

bool myLine::operator < (myLine l){

if(this->getLength()<l.getLength())return true;

return false;

}

bool myLine::operator >= (myLine l){

if(this->getLength()>=l.getLength())return true;

return false;

}

bool myLine::operator <= (myLine l){

if(this->getLength()<=l.getLength())return true;

return false;

}

double myLine::slope(){

if(p2.getX()!=p1.getX()){

return ((p1.getY()-p2.getY())/(p1.getX()-p2.getX()));

}

}

double myLine::intercept(){

if(p2.getX()!=p1.getX()){

return (p2.getY()-(this->slope()*p2.getX()));

}

}

//progExam1.cpp

#include"myLine.cpp"

int main(){

myPoint p1,p2;

cin>>p1;

cin>>p2;

myLine l(p1,p2);

cout<<l.slope()<<" "<<l.intercept();

return 0;

}