}

The program defines a class called Point, which represents a point in 2D space. The class has two private data members x and y, representing the point's coordinates. The class also has a constructor that takes two integers and initializes the coordinates, and a public method Print that outputs the coordinates to the console.

The class also defines two operator overloading functions, += and -=, which add and subtract points, respectively. These functions modify the x and y coordinates of the current object, based on the x and y coordinates of the argument.

In the main function, two Point objects are created, P1 and P2, with initial coordinates (5,7) and (4,3), respectively. The Print method is then called on both objects to output their coordinates.

The += operator is then used to add P2 to P1, modifying the coordinates of P1. The Print method is called again on P1 to output its new coordinates.

Finally, the -= operator is used to subtract P1 from P2, modifying the coordinates of P2. The Print method is called again on P2 to output its new coordinates

#include iostreamhclass Point publicPointint i int j x = i; y = j; void Print cout x y endl; void operator += Point p x += px; y += py; void operator -= Point p x -= px; y -= py; private i

原文地址: https://www.cveoy.top/t/topic/fiO1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录