Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Point{
- int x_;
- int y_;
- public:
- Point(int x=0, int y=0){
- x_=x;
- y_=y;
- }
- void print(){
- cout << "("<< x_<< "," << y_ << ")"<<endl;
- }
- void move_by(Point p){
- set_x(x_+p.get_x());
- set_y(y_+p.get_y());
- }
- void translate(int transl_x, int transl_y){
- x_+=transl_x;
- y_+=transl_y;
- }
- int get_x(){
- return x_;
- }
- void set_x(int x){
- x_=x;
- }
- int get_y(){
- return y_;
- }
- void set_y(int y){
- y_=y;
- }
- };
- int main(){
- Point p1;
- p1.print();
- p1.set_x(10);
- Point p2(10,10);
- p2.print();
- cout << "x of p1:" << p1.get_x() << endl;
- p2.set_x(50);
- p2.move_by(p1);
- cout << "P2 x:" << p2.get_x() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement