Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point{
  5. int x_;
  6. int y_;
  7. public:
  8. Point(int x=0, int y=0){
  9. x_=x;
  10. y_=y;
  11. }
  12.  
  13. void print(){
  14. cout << "("<< x_<< "," << y_ << ")"<<endl;
  15. }
  16.  
  17. void move_by(Point p){
  18. set_x(x_+p.get_x());
  19. set_y(y_+p.get_y());
  20. }
  21.  
  22. void translate(int transl_x, int transl_y){
  23. x_+=transl_x;
  24. y_+=transl_y;
  25. }
  26.  
  27. int get_x(){
  28. return x_;
  29. }
  30.  
  31. void set_x(int x){
  32. x_=x;
  33. }
  34.  
  35. int get_y(){
  36. return y_;
  37. }
  38.  
  39. void set_y(int y){
  40. y_=y;
  41. }
  42. };
  43.  
  44. int main(){
  45.  
  46. Point p1;
  47. p1.print();
  48. p1.set_x(10);
  49.  
  50. Point p2(10,10);
  51. p2.print();
  52.  
  53. cout << "x of p1:" << p1.get_x() << endl;
  54. p2.set_x(50);
  55.  
  56. p2.move_by(p1);
  57. cout << "P2 x:" << p2.get_x() << endl;
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement