Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int avg(vector<float> a){
- float res = 0;
- for (int i = 0; i < a.size(); i++)
- res += a[i];
- return (res / a.size());
- }
- class vec2d {
- public:
- float x;
- float y;
- vec2d() : x(0), y(0) {}
- vec2d(float a,float b) : x(a), y(b){}
- void print(){
- cout << x << "\t" << y << endl;
- }
- float dot(vec2d other){
- return (x * other.x + y * other.y);
- }
- vec2d operator + (vec2d other){
- return vec2d(x + other.x, y + other.y);
- }
- vec2d operator - (vec2d other){
- return vec2d(x - other.x, y - other.y);
- }
- vec2d operator * (float a){
- return vec2d(x * a, y * a);
- }
- vec2d operator / (float a){
- return vec2d(x / a, y / a);
- }
- };
- int main()
- {
- /*vector<float> arr;
- for (float i = 0; i < 9; i+= 1.1)
- arr.push_back(i*i);
- for (float i = 0; i < 9; i++)
- cout << arr[i] << "\n";
- cout << "--------------------------------------" << endl;
- cout << avg(arr) << endl;*/
- vec2d a(4,2);
- a.print();
- vec2d b(-1,-2);
- vec2d c = a - b;
- c.print();
- //cout << a.dot(b) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement