forked from ladyusa/cpp-course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
32 lines (27 loc) · 731 Bytes
/
Copy pathvector.cpp
File metadata and controls
32 lines (27 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
class Vector{
private:
int start_x_, start_y_;
int end_x_, end_y_;
public:
Vector(int sx,int sy, int ex, int ey): start_x_(sx), start_y_(sy),
end_x_(ex), end_y_(ey) {}
/* this: (1, 1) -> (2, 2)
* other: (10, 10) -> (20, 20)
* result: (11, 11) -> (22, 22)
*/
Vector Add(Vector other){
int result_sx = this->start_x_ + other.start_x_;
int result_sy = this->start_y_ + other.start_y_;
int result_ex = this->end_x_ + other.end_x_;
int result_ey = this->end_y_ + other.end_y_;
Vector result(result_sx, result_sy, result_ex, result_ey);
return result;
}
};
int main(){
Vector v1(1,1,2,2);
Vector v2(10, 10, 20, 20);
Vector v3 = v1.Add(v2);
}