Advertisement
Josif_tepe

Untitled

Oct 28th, 2023
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class Point {
  5.     int x;
  6.     int y;
  7.    
  8. public:
  9.     Point() {}
  10.     Point(int _x, int _y) {
  11.         x = _x;
  12.         y = _y;
  13.     }
  14.     void set_x(int _x) {
  15.         x = _x;
  16.     }
  17.     void set_y(int _y) {
  18.         y = _y;
  19.     }
  20.     int get_x() {
  21.         return x;
  22.     }
  23.     int get_y() {
  24.         return y;
  25.     }
  26.    
  27.     Point operator + (Point tmp) {
  28.         Point result(x + tmp.x, y + tmp.y);
  29.         return result;
  30.     }
  31.     Point operator - (Point tmp) {
  32.         Point result(x - tmp.x, y - tmp.y);
  33.         return result;
  34.     }
  35.     Point operator * (Point tmp) {
  36.         Point result(x * tmp.x, y * tmp.y);
  37.         return result;
  38.     }
  39.     Point operator / (Point tmp) {
  40.         Point result(x / tmp.x, y / tmp.y);
  41.         return result;
  42.     }
  43.    
  44.    
  45. };
  46. int main()
  47. {
  48.     Point p1(1, 2);
  49.     Point p2(3, 4);
  50.    
  51.     Point p3 = p1 + p2;
  52.     Point p4 = p1 - p2;
  53.     Point p5 = p1 * p2;
  54.     Point p6 = p1 / p2;
  55.     cout << p3.get_x() << " " << p3.get_y() << endl;
  56.     cout << p4.get_x() << " " << p4.get_y() << endl;
  57.     cout << p5.get_x() << " " << p5.get_y() << endl;
  58.     cout << p6.get_x() << " " << p6.get_y() << endl;
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement