1
0
forked from s444409/POB_2019

Added z7"

This commit is contained in:
Marcin Kostrzewski 2019-05-05 21:01:16 +02:00
parent 4fc3b7661f
commit be1ce93864
8 changed files with 113 additions and 0 deletions

0
zad2_2 Executable file → Normal file
View File

0
zad3_1 Executable file → Normal file
View File

0
zad5_1 Executable file → Normal file
View File

BIN
zad7_1 Normal file

Binary file not shown.

59
zad7_1.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <iostream>
#include <string>
#include <sstream>
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;
}

BIN
zad7_2 Normal file

Binary file not shown.

34
zad7_2.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
template <typename num>
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<float> vec1 = Vec2<float>(5.5f,1.2f);
Vec2<float> vec2 = Vec2<float>(3.4f,4.2f);
Vec2<float> vec3 = vec1.add(vec2);
cout << vec3.toString() << endl;
}

20
zad7_3.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
template <typename type>
class Array {
private:
type* ptrs;
Array(){}
~Array(){}
public:
Array& operator new [](){
Array();
return *this;
}
void operator delete [](){
~Array();
}
}