Aug 4th, 2021 (edited)
567
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2.
3. enum Quadrants { ZeroPoint, First, Second, Third, Fourth, XPositive, XNegative, YPositive, YNegative };
4.
5. class Point
6. {
7.     int x;
8.     int y;
9. public:
10.     Point() = default;
11.     Point(int pX, int pY) : x{ pX }, y{ pY } {}
12.     Point& setX(int pX) { x = pX; return *this; }
13.     Point& setY(int pY) { y = pY; return *this; }
14.     int getX()const { return x; }
15.     int getY()const { return y; }
16.     void show() const
17.     {
18.         std::cout << '(' << x << ',' << y << ')';
19.     }
20.     friend double distance(const Point& p1, const Point& p2);
21.     friend int quadrant(const Point& p)
22.     {
23.         if ((!p.y and !p.x)) { return Quadrants::ZeroPoint; }
24.         if (!p.y) { return p.x > 0 ? Quadrants::XPositive : Quadrants::XNegative; }
25.         if (!p.x) { return p.y > 0 ? Quadrants::YPositive : Quadrants::YNegative; }
26.         if (p.y > 0)
27.         {
29.         }
31.     }
32. };
33.
34. double distance(const Point& p1, const Point& p2)
35. {
36.     auto xLength{ p2.x - p1.x };
37.     auto yLength{ p2.y - p1.y };
38.     return sqrt(xLength * xLength + yLength * yLength);
39. }
40.
42. {
48.     else if (quadrant == Quadrants::XPositive) { std::cout << "X axis positive"; }
49.     else if (quadrant == Quadrants::XNegative) { std::cout << "X axis negative"; }
50.     else if (quadrant == Quadrants::YPositive) { std::cout << "Y axis positive"; }
51.     else if (quadrant == Quadrants::YNegative) { std::cout << "Y axis negative"; }
52. }
53.
54. int main()
55. {
56.     Point p1{ 5,5 };
57.     Point p2{ 10,10 };
58.
59.     std::cout << "Distance between p1 and p2 is: " << distance(p1, p2) << '\n';
60.
61.     const int testCases{ 9 };
62.     Point points[testCases]{
63.         {0,0},
64.         {1,1},
65.         {-1,1},
66.         {-1,-1},
67.         {1,-1},
68.         {1,0},
69.         {-1,0},
70.         {0,1},
71.         {0,-1}
72.     };
73.
74.     for (int i{ 0 }; i < testCases; ++i)
75.     {
76.         points[i].show();
77.         std::cout << ' ';