• API
• FAQ
• Tools
• Archive
daily pastebin goal
19%
SHARE
TWEET

# Untitled

a guest May 16th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
2. #include <iostream>
3. #include <vector>
4.
5. using namespace std;
6.
7. class Point{
8.   float x,y;
9. public:
10.   float getX() const{return x;}
11.   void setX(float value){x=value;}
12.   float getY() const{return y;}
13.   void setY(float value){y=value;}
14. };
15.
16. vector <Point>inRectangle(vector <Point> &vec, Point p, Point q){
17.     vector <Point> result;
18.     for(int i=0; i< vec.size(); i++){
19.         Point &tmp=vec[i];
20.         if(p.getX()<=tmp.getX() && q.getX()>=tmp.getX() && p.getY()>=tmp.getY() && q.getY()<=tmp.getY())
21.             result.push_back(tmp);
22.
23.     }
24.     return result;
25. }
26.
27. int main()
28. {
29.     vector<Point> vec(10);
30.     for(int i=0; i<vec.size(); i++){
31.         vec[i].setX(i);
32.         vec[i].setY(2*i);
33.     }
34.
35.     Point p, q;
36.     p.setX(0);
37.     p.setY(6);
38.     q.setX(6);
39.     q.setY(2);
40.     vector<Point> vec2;
41.     vec2=inRectangle(vec, p, q);
42.
43.     for(int i=0; i<vec2.size(); i++){
44.         cout << vec2[i].getX() << ", " << vec2[i].getY() << endl;
45.     }
46.
47.     return 0;
48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top