#include <iostream>
class Point {
private:
int x;
int y;
static int numPoints;
public:
// Constructors
Point() : x(0), y(0) {
numPoints++;
}
Point(int x, int y) : x(x), y(y) {
numPoints++;
}
// Copy constructor
Point(const Point &other) : x(other.x), y(other.y) {
numPoints++;
}
// Destructor
~Point() {
numPoints--;
}
// Overloaded input stream operator
friend std::istream& operator>>(std::istream &in, Point &point) {
in >> point.x >> point.y;
return in;
}
// Overloaded output stream operator
friend std::ostream& operator<<(std::ostream &out, const Point &point) {
out << point.x << " " << point.y;
return out;
}
// Overloaded unary minus (-) operator
Point operator-() const {
return Point(-x, -y);
}
// Overloaded binary plus (+) operator
Point operator+(const Point &other) const {
return Point(x + other.x, y + other.y);
}
// Overloaded postfix increment (++) operator
Point operator++(int) {
Point temp(*this);
x++;
y++;
return temp;
}
// Overloaded equality (==) operator
bool operator==(const Point &other) const {
return (x == other.x) && (y == other.y);
}
// Overloaded subscript operator for access to x and y
int operator[](int index) const {
return (index == 0) ? x : ((index == 1) ? y : 0);
}
// Const member function to get the number of points
static int getNumPoints() {
return numPoints;
}
};
// Initialize static member numPoints
int Point::numPoints = 0;
int main() {
std::cout << std::endl;
Point p1;
Point p2(3, 5);
std::cout << "Enter x and y values: ";
std::cin >> p1;
std::cout << p1 << " " << -p2 << std::endl;
std::cout << (p1 + p2) << std::endl;
std::cout << (p2++) << std::endl;
std::cout << p2 << std::endl;
std::cout << (p1 == p2) << std::endl;
std::cout << p1[1] << " " << p1[0] << std::endl; // Corrected the order of indices
std::cout << Point::getNumPoints() << std::endl;
std::cout << std::endl;
return 0;
}