fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point{
  5. public: int x, y;
  6.  
  7. Point(int x, int y){
  8. this->x=x;
  9. this->y=y;
  10. }
  11. Point operator*(int p){
  12. int x=this->x*p;
  13. int y=this->y*p;
  14. return Point(x, y);
  15. }
  16. Point operator+=(Point p){
  17. this->x+=p.x;
  18. this->y+=p.y;
  19. return *this;
  20. }
  21. void display(){
  22. cout<<"("<<x<<", "<<y<<")";
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. Point p1(1, 2);
  29. Point p2(3, 4);
  30. Point p4(11, 11);
  31.  
  32. p1+=p2*10; //p1=(31,42)
  33.  
  34. p1.display();
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
(31, 42)