Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Point {
- private:
- int x, y;
- public:
- Point() {}
- Point(int _x, int _y) {
- x = _x;
- y = _y;
- }
- Point(const Point & tmp) {
- x = tmp.x;
- y = tmp.y;
- }
- int get_x() {
- return x;
- }
- int get_y() {
- return y;
- }
- void set_x(int _x) {
- x = _x;
- }
- void set_y(int _y) {
- y = _y;
- }
- Point operator + (Point tmp) {
- Point res(x + tmp.x, y + tmp.y);
- return res;
- }
- Point operator - (Point tmp) {
- Point res(x - tmp.x, y - tmp.y);
- return res;
- }
- Point operator * (Point tmp) {
- Point res(x * tmp.x, y * tmp.y);
- return res;
- }
- Point operator / (Point tmp) {
- Point res(x / tmp.x, y / tmp.y);
- return res;
- }
- void print() {
- cout << x << " " << y << endl;
- }
- };
- int main()
- {
- Point p1(2, 3);
- Point p2(4, 5);
- Point p3 = p1 + p2;
- p3.print();
- Point p4 = p1 - p2;
- p4.print();
- Point p5 = p1 * p2;
- p5.print();
- Point p6 = p1 / p2;
- p6.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement