diff --git a/zad2_2 b/zad2_2 old mode 100755 new mode 100644 diff --git a/zad3_1 b/zad3_1 old mode 100755 new mode 100644 diff --git a/zad5_1 b/zad5_1 old mode 100755 new mode 100644 diff --git a/zad7_1 b/zad7_1 new file mode 100644 index 0000000..b9f747a Binary files /dev/null and b/zad7_1 differ diff --git a/zad7_1.cpp b/zad7_1.cpp new file mode 100644 index 0000000..2037517 --- /dev/null +++ b/zad7_1.cpp @@ -0,0 +1,59 @@ +#include +#include +#include + +using namespace std; + +class Vec2 { + private: + int x,y; + public: + Vec2(int _x, int _y){ + x=_x; + y=_y; + } + string toString(){ + stringstream s; + s << "[" << x << ", " << y << "]"; + return s.str(); + } + Vec2 operator+(const Vec2& vec){ + return Vec2(x+vec.x, y+vec.y); + } + Vec2 operator-(const Vec2& vec){ + return Vec2(x-vec.x, y-vec.y); + } + Vec2& operator+=(const Vec2& vec){ + x=vec.x+x; + y=vec.y+y; + return *this; + } + Vec2& operator-=(const Vec2& vec){ + x=vec.x-x; + y=vec.y-y; + return *this; + } + float operator*(const Vec2& vec){ + return (float)x*vec.x + (float)y+vec.y; + } + bool operator==(const Vec2& vec){ + if(x==vec.x && y==vec.y) return 1; + else return 0; + } + bool operator!=(const Vec2& vec){ + if(x==vec.x && y==vec.y) return 0; + else return 1; + } +}; + +int main(){ + Vec2 vec1 = Vec2(5,1); + Vec2 vec2 = Vec2(3,4); + Vec2 vec3 = vec1 + vec2; + cout << vec3.toString() << endl; + vec3+=vec2; + cout << vec3.toString() << endl; + vec3-=vec1; + cout << vec3.toString() << endl; + cout << vec3*vec2 << endl; +} \ No newline at end of file diff --git a/zad7_2 b/zad7_2 new file mode 100644 index 0000000..74f246b Binary files /dev/null and b/zad7_2 differ diff --git a/zad7_2.cpp b/zad7_2.cpp new file mode 100644 index 0000000..088e04d --- /dev/null +++ b/zad7_2.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace std; + +template +class Vec2 { + private: + num x,y; + public: + Vec2(num _x, num _y){ + x=_x; + y=_y; + } + string toString(){ + stringstream s; + s << "[" << x << ", " << y << "]"; + return s.str(); + } + Vec2 add(const Vec2& vec){ + return Vec2(x+vec.x, y+vec.y); + } + float multiply(const Vec2& vec){ + return (float)x*vec.x + (float)y*vec.y; + } +}; + +int main(){ + Vec2 vec1 = Vec2(5.5f,1.2f); + Vec2 vec2 = Vec2(3.4f,4.2f); + Vec2 vec3 = vec1.add(vec2); + cout << vec3.toString() << endl; +} \ No newline at end of file diff --git a/zad7_3.cpp b/zad7_3.cpp new file mode 100644 index 0000000..02741e2 --- /dev/null +++ b/zad7_3.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; + +template +class Array { + private: + type* ptrs; + Array(){} + ~Array(){} + public: + Array& operator new [](){ + Array(); + return *this; + } + void operator delete [](){ + ~Array(); + } + +} \ No newline at end of file