Advertisement
High_Light

векторы

Apr 24th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int avg(vector<float> a){
  7.     float res = 0;
  8.     for (int i = 0; i < a.size(); i++)
  9.         res += a[i];
  10.     return (res / a.size());
  11. }
  12. class vec2d {
  13. public:
  14.     float x;
  15.     float y;
  16.     vec2d() : x(0), y(0) {}
  17.     vec2d(float a,float b) : x(a), y(b){}
  18.     void print(){
  19.         cout << x << "\t" << y << endl;
  20.     }
  21.     float dot(vec2d other){
  22.         return (x * other.x + y * other.y);
  23.     }
  24.     vec2d operator + (vec2d other){
  25.         return vec2d(x + other.x, y + other.y);
  26.     }
  27.     vec2d operator - (vec2d other){
  28.         return vec2d(x - other.x, y - other.y);
  29.     }
  30.     vec2d operator * (float a){
  31.         return vec2d(x * a, y * a);
  32.     }
  33.     vec2d operator / (float a){
  34.         return vec2d(x / a, y / a);
  35.     }
  36. };
  37.  
  38. int main()
  39. {
  40.     /*vector<float> arr;
  41.     for (float i = 0; i < 9; i+= 1.1)
  42.         arr.push_back(i*i);
  43.     for (float i = 0; i < 9; i++)
  44.         cout << arr[i] << "\n";
  45.     cout << "--------------------------------------" << endl;
  46.     cout << avg(arr) << endl;*/
  47.     vec2d a(4,2);
  48.     a.print();
  49.     vec2d b(-1,-2);
  50.     vec2d c = a - b;
  51.     c.print();
  52.  
  53.     //cout << a.dot(b) << endl;
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement