Implement the Point class code for this up to the isHigher m
Implement the Point class (code for this up to the isHigher method was discussed in the lecture). The class has the following instance variables: • x coordinate (an int) • y coordinate (an int) and the following methods: • Constructor that sets the x and y coordinates • Get and set methods • Method equals if this point is equal to another point object (if the x and y coordinates are the same). • Method isHigher if this point is higher than another point object (Note that we assume that the top left corner is the coordinate 0,0). • Method findDistance that calculates the distance between this point and another point. (Formula for the distance between two points (x1,y1) and (x2,y2) is square root of ((x2-x1)2 + (y2-y1)2) Test the class. In the demo program, construct four points p1, p2, p3 and p4 using user-defined values. Determine • Which point is the highest. (If more than one point is at the same height, you may report any one point). • Whether the distance p1à p2 is more than the distance p3à p4, or p3à p4 is more than p1àp2, or whether they are the same.
* I am using JGrasp
*Please complete without: \"#include using namespace std;\" since we haven\'t used them in my class
Implement the class for this up to the isHigh lecture). The class has the following instance variables er method was discussed in the x coordinate (an int y coordinate (an int) and the following methods Constructor that sets the x and y coordinates Get and set methods Method equals if this point is equal to another point object (if the x and y coordinates are the same). Method isHigher if this point is higher than another point object (Note that we assume that the top left corner is the coordinate 0,0).Solution
// C++ code
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <math.h>
using namespace std;
class Point
{
public:
int x;int y;
Point(int a,int b)
{
x=a;
y=b;
}
void setX(int a)
{
x=a;
}
void setY(int b)
{
y=b;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
float findDistance(Point p)
{
return sqrt( (p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
int isEqual(Point p)
{
if(p.x == x && p.y == y)
return 1;
else
return 0;
}
int isHigher(Point p)
{
if(p.y > y)
return 1;
return 0;
}
};
int main(int argc, char const *argv[])
{
int x;int y;
cout<<\"Enter the x and y coordinates of point1: \";
cin>>x>>y;
Point p1(x,y);
cout<<\"Enter the x and y coordinates of point2: \";
cin>>x>>y;
Point p2(x,y);
cout<<\"Enter the x and y coordinates of point3: \";
cin>>x>>y;
Point p3(x,y);
cout<<\"Enter the x and y coordinates of point4: \";
cin>>x>>y;
Point p4(x,y);
if(p1.isHigher(p2)==1 && p1.isHigher(p3)==1 && p1.isHigher(p4)==1)
cout << \"[\" << p1.x << \",\" <<p1.y << \"] is the highest point\" << endl;
else if(p2.isHigher(p1)==1 && p2.isHigher(p3)==1 && p2.isHigher(p4)==1)
cout << \"[\" << p2.x << \",\" <<p2.y << \"] is the highest point\" << endl;
else if(p3.isHigher(p2)==1 && p3.isHigher(p1)==1 && p3.isHigher(p4)==1)
cout << \"[\" << p3.x << \",\" <<p3.y << \"] is the highest point\" << endl;
else
cout << \"[\" << p4.x << \",\" <<p4.y << \"] is the highest point\" << endl;
float d1=p1.findDistance(p2);
float d2=p3.findDistance(p4);
cout<<\"The distance between [\"<<p1.x<<\",\"<<p1.y<<\"] and [\"<<p2.x<<\",\"<<p2.y<<\"] is \"<<d1<<endl;
cout<<\"The distance between [\"<<p3.x<<\",\"<<p3.y<<\"] and [\"<<p4.x<<\",\"<<p4.y<<\"] is \"<<d2<<endl;
if(d2>d1)
{
cout<<\"[\"<<p1.x<<\",\"<<p1.y<<\"] ----> \"<<\"[\"<<p2.x<<\",\"<<p2.y<<\"] is shorter than \"<<\"[\"<<p3.x<<\",\"<<p3.y<<\"]--------> [\"<<p4.x<<\",\"<<p4.y<<\"]\ \";
}
else
{
cout<<\"[\"<<p1.x<<\",\"<<p1.y<<\"] ----> [\"<<\"[\"<<p2.x<<\",\"<<p2.y<<\"] is longer than \"<<\"[\"<<p3.x<<\",\"<<p3.y<<\"]--------> [\"<<p4.x<<\",\"<<p4.y<<\"]\ \";
}
return 0;
}
/*
output:
Enter the x and y coordinates of point1: 8 9
Enter the x and y coordinates of point2: 4 3
Enter the x and y coordinates of point3: 2 1
Enter the x and y coordinates of point4: 5 6
[2,1] is the highest point
The distance between [8,9] and [4,3] is 7.2111
The distance between [2,1] and [5,6] is 5.83095
[8,9] ----> [[4,3] is longer than [2,1]--------> [5,6]
*/


